p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Re: testing browser and version


Message #1 by "jpryde" <jjkpryde@c...> on Sun, 31 Mar 2002 18:47:12 -0500
   :
>The problem I'm having is that the data contained in $HTTP_USER_AGENT
is a
>string variable. Thus, there is no way I can see to split it up into
>meaningful chunks that can be used in an "if" test. Because it's a
string, I
>can't use implode(), which is one thing I did try.

>Anyone know of a way to do this, short of using regular expressions?
  :


This is a good question as there doesn't seem to be any standard for the
format of the string returned by $HTTP_USER_AGENT.  It's a sad statement
of the browser industry in my opinion.  Anyway, If you know what the
choices are, you might try just using string search functions such as
strstr() which returns either a substring starting with your match or
FALSE.  You wouldn't really care about the substring, just that you
don't get FALSE.

So one solution might be something like:

if  (strstr($HTTP_USER_AGENT, "MSIE 5.0"))
  {
    // handle IE version 5.0 browsers
     }
else 
    if  (strstr($HTTP_USER_AGENT, "MSIE 4.0"))
        {
       // handle IE vedrsion 4.0 browsers
        }

.etc.


Admittedly, this is kind of kludgy and I'm anxious to see some more
elegant solution by a more experienced php developer.


- Jason

P.s.  Wouldn't it be cool if all browser companies just provided a
bitmap that you could XOR with predefined bit patterns, each bit pattern
assigned to an industry standard code for a particular browser or
better, a unique browser capability.   E.g.   00000001 = javascript
enabled, 00000010 = frames enabled, 00000011=frames and javascript,etc.
Then you could control which features you utilized for each site
dynamically.   Oh well.





Jason Pryde
 



  Return to Index