Using Php is it possible to detect exact OS even if the browser agent value is altered?
Here is the case
If someone override Firefox useragent value using "general.useragent.override"
Actual: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0
Override: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10
$_SERVER['HTTP_USER_AGENT'] value will be totally fake. it's not useful even to detect correct Operating System.
Is there any Php solution in this situation?
Thanks.
No, it is not possible. The only information you have is that supplied by the User-agent header, and if a user wants to send false information there is nothing you can do to detect it.
You can still use JavaScript to find the screen size but not the os this is how to
<script type="text/javascript">
document.write(screen.width+'x'+screen.height);
</script>
but this can be changed by the client anyway as its on the client side on ios there is one way by setting up a mobile management profile temp to very the device but thats a lot of work for the client so only do that if you have to
But in most cases you cannot very its not mod
Related
How would I force HTTP (Not HTTPS), while getting the source code of: http://www.youtube.com/watch?v=2YqEDdzf-nY?
I've tried using get_file_contents, but it goes to HTTPS.
There is no way, because google forces you to use https. It will not accept longer unsecure connection.
They even start to downrank websites, which are not on SSL.
As for your Comment, i have done a little bit more research.
Maybe it is depended on the user-agent. I have no time to confirm this.
Try CURL with this User Agent:
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101
I've been searching for an answer here and in Google but can't seem to have a definite answer, this is my first post in StackOverflow but have been a regular visitor for some years and I have learned a lot from this site, so thanks!
My problem is with Expedia's API regarding Hotel information: http://developer.ean.com/docs/read/hotel_info/examples/XML_Default_Content
My problematic URL is:
http://api.ean.com/ean‑services/rs/hotel/v3/info?cid=55505&minorRev=1&apiKey=9kxdnz8ngbf7gmwkzm4qkgjw&customerSessionId=0ABAA850-419E-A913-D072-4A24A390607C&customerUserAgent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0&customerIpAddress=2.50.181.154&locale=en_UScurrencyCode=USD&xml=1175480
I'm getting a "596 Service Not Found" error.
I apologize if this has been asked before, and many thanks for the help!!!
The example in EAN's Developer Hub for making a Hotel Info request has been fixed.
The problem:
http://api.ean.com/ean‑services/rs/hotel/v3/info?
The solution:
http://api.ean.com/ean-services/rs/hotel/v3/info?
You also didn't enter the xml parameter correctly. It should have been like this:
http://api.ean.com/ean-services/rs/hotel/v3/info?cid=55505&minorRev=1&apiKey=9kxdnz8ngbf7gmwkzm4qkgjw&customerUserAgent=Mozilla/5.0 (Macintosh; Intel Mac 0OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0&customerIpAddress=2.50.181.154&locale=en_US¤cyCode=USD&xml=<HotelInformationRequest>
<hotelId>122212</hotelId>
<options>0</options>
</HotelInformationRequest>
You could just forget about using xml and use the REST format:
http://api.ean.com/ean-services/rs/hotel/v3/info?cid=55505&minorRev=1&apiKey=9kxdnz8ngbf7gmwkzm4qkgjw&customerUserAgent=Mozilla/5.0 (Macintosh; Intel Mac 0OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0&customerIpAddress=2.50.181.154&locale=en_US¤cyCode=USD&hotelId=122212&options=0
By the way, I just found a SDK for Android from Expedia Affiliate Network. https://github.com/ExpediaInc/ean-android
You can Try this its working good.
http://api.ean.com/ean-services/rs/hotel/v3/info?cid=55505&minorRev=1&apiKey=9kxdnz8ngbf7gmwkzm4qkgjw&customerSessionId=&customerUserAgent=Mozilla/5.0%20%28Macintosh;%20Intel%20Mac%20OS%20X%2010.8;%20rv:19.0%29%20Gecko/20100101%20Firefox/19.0&customerIpAddress=&locale=en_UScurrencyCode=USD
You can add this xml to your code
&xml=<HotelInfo><hotelId>407696</hotelId><city></city><options>DEFAULT</options></HotelInfo>
I have such address example.com/page1. For example visitor's user agent is like this: Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146. I run session_id() and PHP Session ID is 12345. I can see "sess_12345" file inside temporary folder. It has all session variables in it.
After some processing I redirect him/her to example.com/page2. Visitor's user agent changes to this: Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146 Twitter for iPhone. I run session_id() again and find out that ID is still 12345. But when I check "sess_12345" file, I see that it is deleted.
This happens only when users come to my website from "Twitter for iPhone" application. I guess session file is deleted because of user-agent change, but I'm not sure. What can be the cause?
(Sessions work successfully except this case. I use CakePHP 2.4)
Cake has a setting which will check the user agent of the browser. If it changes will destroy the session. Turn this setting off:
Session.checkAgent
When a search engine visits a webpage, what does get_browser() function and $_SERVER['HTTP_USER_AGENT'] return?
Also, what is the other possible evidence that PHP offers when a search engine crawls a webpage?
The get_browser() function attempts to determine the browser's features (in array) but dont count too much on it because of the non standard user-agents; instead, for a serious app, build your own.
the $_SERVER["HTTP_USER_AGENT"] is a long string "describing" the user's browser and can be used as first parameter in the above function (optional); A tip: use this one to uncover user's browser instead of get_browser() itself! Also be prepared for a missing user agent as well! An example of this string is this:
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3
a search engine or robot or spider or crawler that follows the rules will visit your page according to the information stored of robots.txt that must exist in your site's root.
Without a robots.txt a spider can crawl the whole site, as long as it find links inside your pages; if you have this file you can program it so to tell the spider what to search; NOTE: this rule applies only to "good" spiders and not the bad ones
get_browser() & $_SERVER['HTTP_USER_AGENT'] will return you the Useragents, it should look like this :
Google :
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)
Googlebot-Image/1.0
Bing :
Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b
msnbot/2.0b (+http://search.msn.com/msnbot.htm)
msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)
Yahoo :
Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
-> To fully control (and limit) the crawl don't use robots.txt, use .htaccess or http.conf rules. (good crawler don't give a f*** about your disallow rules half of the time in robots.txt)
i am trying to change user agent in php.ini file as follows.
user_agent="Mozilla/5.0 (iPhone Simulator; U;
CPU iPhone OS 4_3_2 like Mac OD X; en-us)
AppleWebKit/535.17.9(KHTML, like Gecko)
Version/5.0.2 Mobile/8H7Safari/6533.18.5"
after that when i check user agent in my php file with following command and this show that user agent has not been change.
echo $_SERVER['HTTP_USER_AGENT'];
this shows : Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
which is still not iphone user agent which i have set in php.ini file.
so please help me how to set user agent in php.ini file which switch my browser request as iphone browser request.
i have also tried with following command.
ini_set('user_agent', 'Mozilla/5.0 (iPhone Simulator; U;
CPU iPhone OS 4_3_2 like Mac OD X; en-us)
AppleWebKit/535.17.9 (KHTML, like Gecko) Version/5.0.2
Mobile/8H7 Safari/6533.18.5');
this also gives same result and i am unable to switch to iphone browser request.
I'm afraid you've misunderstood. The user_agent setting in php.ini has nothing to do with $_SERVER['HTTP_USER_AGENT].
The setting in php.ini is used as a default for when PHP does HTTP requests, for example with cURL.
$_SERVER['HTTP_USER_AGENT'] contains the user agent that the web browser sent along with its request to your PHP script. That's why it's showing MSIE because you're viewing the page in MSIE.
If you want to send a different user agent from your browser, you'll have to use a browser plugin unless the browser allows you to freely modify it. For example like this.