Connecting Tech Pros Worldwide Forums | Help | Site Map

Send out different content depends on User Agent String

Allerdyce.John@gmail.com
Guest
 
Posts: n/a
#1: Jan 27 '06
Hi,

Is there an easy way in PHP which send outs different content depends
on User Agent String value?
If yes, is there an example/documentation?

Thank you.


Sune Storgaard
Guest
 
Posts: n/a
#2: Jan 27 '06

re: Send out different content depends on User Agent String


Allerdyce.John@gmail.com wrote:[color=blue]
> Hi,
>
> Is there an easy way in PHP which send outs different content depends
> on User Agent String value?
> If yes, is there an example/documentation?[/color]

Im not sure what exactly you want to achieve, but this reserved variable
will contain the useragent string (which can be forged easely)

$_SERVER['HTTP_USER_AGENT']

It will return something like this:
"Mozilla/5.0 (Windows; U; Windows NT 5.1; da; rv:1.8) Gecko/20051111
Firefox/1.5"Use some str function to check for occurences of "mozilla" and
do some conditional code based on result ?A little untested
example:<?php$ouragent = $_SERVER['HTTP_USER_AGENT']; // could be fitted
into the IF sentence if (substr_count($ouragent,"Mozilla")!=0) {
echo "Mozilla..maybe";}else{ echo "some other stuff"}?>


NC
Guest
 
Posts: n/a
#3: Jan 27 '06

re: Send out different content depends on User Agent String


Allerdyce.John@gmail.com wrote:[color=blue]
>
> Is there an easy way in PHP which send outs different content
> depends on User Agent String value?[/color]

Yes. There is a superglobal variable $_SERVER['HTTP_USER_AGENT']
[color=blue]
> If yes, is there an example/documentation?[/color]

Here is the documentation on the subject in its entirety:

'HTTP_USER_AGENT'
Contents of the User-Agent: header from the current request,
if there is one. This is a string denoting the user agent being
which is accessing the page. A typical example is: Mozilla/4.5
[en] (X11; U; Linux 2.2.9 i586). Among other things, you can
use this value with get_browser() to tailor your page's output
to the capabilities of the user agent.

Source:
http://www.php.net/manual/en/reserve...riables.server

Cheers,
NC

d
Guest
 
Posts: n/a
#4: Jan 27 '06

re: Send out different content depends on User Agent String



<Allerdyce.John@gmail.com> wrote in message
news:1138340794.511698.285410@g44g2000cwa.googlegr oups.com...[color=blue]
> Hi,
>
> Is there an easy way in PHP which send outs different content depends
> on User Agent String value?
> If yes, is there an example/documentation?[/color]

Be aware that the user agent string can be changed, and therefor isn't as
accurate as detecting the browser using javascript (but, on the other hand,
is completely transparent)
[color=blue]
> Thank you.
>[/color]

dave


Closed Thread