1
0
Fork 0
mirror of https://github.com/Findus23/devicedetector.net.git synced 2024-09-19 15:43:46 +02:00

error handling and limit of ua length

This commit is contained in:
Lukas Winkler 2019-09-04 11:08:02 +02:00
parent 1f615801de
commit ab7a3e4c4b
Signed by: lukas
GPG key ID: 54DE4D798D244853
2 changed files with 15 additions and 3 deletions

View file

@ -12,6 +12,9 @@
<div v-if="tooManyRequests" class="box centered">
There were too many requests. Please wait a minute before reloading the website.
</div>
<div v-if="serverError" class="box centered">
There was an error on the server: <code>{{serverError}}</code>
</div>
<div v-if="gotData">
<div v-if="!dd.clientInfo && !dd.botInfo" class="box centered">
Device Detecter couldn't detect any information about this user agent.
@ -102,7 +105,8 @@ export default Vue.extend({
gotData: false,
processingServerSide: false,
showJSON: false,
tooManyRequests: false
tooManyRequests: false,
serverError: ""
};
},
computed: {
@ -116,6 +120,7 @@ export default Vue.extend({
},
fetchData(ua: string): void {
this.gotData = false;
this.serverError = "";
this.tooManyRequests = false;
this.processingServerSide = true;
const req = new XMLHttpRequest();
@ -124,11 +129,13 @@ export default Vue.extend({
if (req.status === 200) {
this.dd = JSON.parse(req.responseText);
this.gotData = true;
this.processingServerSide = false;
} else if (req.status === 429) {
this.tooManyRequests = true;
this.processingServerSide = false;
} else {
this.serverError = req.responseText;
}
this.processingServerSide = false;
}
};
req.open("GET", baseURL + "?ua=" + ua, true);

View file

@ -23,6 +23,11 @@ if (!empty($_GET["ua"])) {
$userAgent = $_SERVER['HTTP_USER_AGENT'];
}
if (strlen($userAgent) > 1000) {
echo "The user agent has to be shorter than 1000 characters.";
http_response_code(500);
exit();
}
$dd = new DeviceDetector($userAgent);
$dd->setYamlParser(new Symfony());