Created
August 16, 2012 07:47
-
-
Save Martin1982/3368181 to your computer and use it in GitHub Desktop.
A little script to utilize the http://useragentstring.com API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Test script for detecting the OS by user agent string | |
// uses the API from http://www.useragentstring.com | |
// Do not forget to add caching! Continuously hitting the | |
// API is bad for performance of both the API and your | |
// application. | |
$apiParams = array( | |
'uas' => $_SERVER['HTTP_USER_AGENT'], | |
'getJSON' => 'os_name' | |
); | |
$apiLocation = "http://www.useragentstring.com/"; | |
$queryString = http_build_query($apiParams); | |
$requestUrl = $apiLocation . '?' . $queryString; | |
$jsonResponse = file_get_contents($requestUrl); | |
$responseData = json_decode($jsonResponse); | |
echo "<pre>"; | |
echo "Requested api at: " . $requestUrl; | |
echo "\nYour os is: " . $responseData->$apiParams['getJSON']; | |
echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment