Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 27th, 2006, 05:55 AM
Allerdyce.John@gmail.com
Guest
 
Posts: n/a
Default Send out different content depends on User Agent String

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.

  #2  
Old January 27th, 2006, 06:25 AM
Sune Storgaard
Guest
 
Posts: n/a
Default 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"}?>


  #3  
Old January 27th, 2006, 04:15 PM
NC
Guest
 
Posts: n/a
Default 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

  #4  
Old January 27th, 2006, 04:55 PM
d
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles