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-->
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-->