Jump to content

Recommended Posts

Posted

Hello there!

 

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:

 

>$fullbrowser = ($_SERVER["HTTP_USER_AGENT"]);

 

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.

 

>Array
(
   [DOCUMENT_ROOT] => /home/dqzhlhsq/public_html
   [HTTP_HOST] => martinirepublic.com
   [PATH] => /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
   [REMOTE_ADDR] => 209.51.137.10
   [REMOTE_PORT] => 51342
   [SCRIPT_FILENAME] => /home/dqzhlhsq/public_html/browsermac.php
   [SERVER_ADDR] => 209.51.137.10
   [SERVER_ADMIN] => webmaster@martinirepublic.com
   [SERVER_NAME] => www.martinirepublic.com
   [SERVER_PORT] => 80
   [SERVER_SIGNATURE] => <ADDRESS>Apache/1.3.31 Server at www.martinirepublic.com Port 80</ADDRESS>

   [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
   [GATEWAY_INTERFACE] => CGI/1.1
   [SERVER_PROTOCOL] => HTTP/1.0
   [REQUEST_METHOD] => GET
   [QUERY_STRING] => 
   [REQUEST_URI] => /browsermac.php
   [SCRIPT_NAME] => /browsermac.php
   [PATH_TRANSLATED] => /home/dqzhlhsq/public_html/browsermac.php
   [PHP_SELF] => /browsermac.php
   [argv] => Array
       (
       )

 

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?

 

It's to be used in a super simple script:

 

><?php

$fullbrowser = $_SERVER["HTTP_USER_AGENT"];

$agent = strpos($fullbrowser,'Mac');

if ($agent === false)
 $browser = 'mac';
else
 $browser = 'other';

if ($browser == 'mac')
echo ('<link rel="stylesheet" type="text/css" href="MRmac.css" />'); 
else
echo ('<link rel="stylesheet" type="text/css" href="MR.css" />');

?>

 

Thanks for the help!

Posted

I can see that the variable HTTP_USER_AGENT does have data in it:

 

http://martinirepublic.com/phpinfo.php

 

So why doesn't it show in the $_SERVER array?

 

 

 

I also thought to use get_browser(), but it can't find the browscap.ini file.

 

 

Is this something I can get help with from TCH Tech Support?

Posted

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!

Posted

Hmmm, I am starting to worry,

more and more people here are talking to themselfs :unsure:

 

 

Seriously, it sometimes helps to layout a problem for others to see

and then you can also see it with fresh eyes.

 

Are the variables you picked,

being also used in your CMS somewhere?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...