Basic Php Browser Sniffer

liunx

Guest
Hello there!<br /><br />I'm trying to run a very simple 'browser sniffer' so I can serve a different CSS sheet to IE/Mac users. However, I can't for the life of me get a proper return from this:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$fullbrowser = ($_SERVER["HTTP_USER_AGENT"]);<!--c2--></div><!--ec2--><br /><br />It doesn't return any data at all, no matter which browser I'm using (checking with Firefox, IE and IE/Mac). I printed out the whole $_SERVER array, and sure enough - there's no user agent in there.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Array<br />(<br />    [DOCUMENT_ROOT] => /home/dqzhlhsq/public_html<br />    [HTTP_HOST] => martinirepublic.com<br />    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin<br />    [REMOTE_ADDR] => 209.51.137.10<br />    [REMOTE_PORT] => 51342<br />    [SCRIPT_FILENAME] => /home/dqzhlhsq/public_html/browsermac.php<br />    [SERVER_ADDR] => 209.51.137.10<br />    [SERVER_ADMIN] => <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --><br />    [SERVER_NAME] => <!-- w --><a class="postlink" href="http://www.martinirepublic.com">www.martinirepublic.com</a><!-- w --><br />    [SERVER_PORT] => 80<br />    [SERVER_SIGNATURE] => <ADDRESS>Apache/1.3.31 Server at <!-- w --><a class="postlink" href="http://www.martinirepublic.com">www.martinirepublic.com</a><!-- w --> Port 80</ADDRESS><br /><br />    [SERVER_SOFTWARE] => Apache/1.3.31 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.7 FrontPage/5.0.2.2634a mod_ssl/2.8.18 OpenSSL/0.9.7a<br />    [GATEWAY_INTERFACE] => CGI/1.1<br />    [SERVER_PROTOCOL] => HTTP/1.0<br />    [REQUEST_METHOD] => GET<br />    [QUERY_STRING] => <br />    [REQUEST_URI] => /browsermac.php<br />    [SCRIPT_NAME] => /browsermac.php<br />    [PATH_TRANSLATED] => /home/dqzhlhsq/public_html/browsermac.php<br />    [PHP_SELF] => /browsermac.php<br />    [argv] => Array<br />        (<br />        )<!--c2--></div><!--ec2--><br /><br />Why is there no user agent listed? Since I'm getting the same non-return everywhere (checking from two different machines) I'm assuming this is a server thing. Is there another way to get the $HTTP_USER_AGENT string?<br /><br />It's to be used in a super simple script:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br />$fullbrowser = $_SERVER["HTTP_USER_AGENT"];<br /><br />$agent = strpos($fullbrowser,'Mac');<br /><br />if ($agent === false)<br />  $browser = 'mac';<br />else<br />  $browser = 'other';<br /><br />if ($browser == 'mac')<br /> echo ('<link rel="stylesheet" type="text/css" href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"MRmac.css" />'); <br />else<br /> echo ('<link rel="stylesheet" type="text/css" href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"MR.css" />');<br /><br />?><!--c2--></div><!--ec2--><br /><br />Thanks for the help!<!--content-->
I can see that the variable HTTP_USER_AGENT does have data in it:<br /><br /><a href="http://martinirepublic.com/phpinfo.php" target="_blank">http://martinirepublic.com/phpinfo.php</a><br /><br />So why doesn't it show in the $_SERVER array? <br /><br /><br /><br />I also thought to use get_browser(), but it can't find the browscap.ini file. <br /><br /><br />Is this something I can get help with from TCH Tech Support?<!--content-->
Ahhh - continued detective work: the problem lies elsewhere. I'm including this file from within a CMS program and that is messing up the variables somehow. So, nevermind - off to another support forum now!<!--content-->
Hmmm, I am starting to worry,<br />more and more people here are talking to themselfs <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> <br /><br /><br />Seriously, it sometimes helps to layout a problem for others to see<br />and then you can also see it with fresh eyes.<br /><br />Are the variables you picked,<br />being also used in your CMS somewhere?<!--content-->
 
Back
Top