468,315 Members | 1,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

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.

Jan 27 '06 #1
3 1675
Al************@gmail.com wrote:
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?


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"}?>
Jan 27 '06 #2
NC
Al************@gmail.com wrote:

Is there an easy way in PHP which send outs different content
depends on User Agent String value?
Yes. There is a superglobal variable $_SERVER['HTTP_USER_AGENT']
If yes, is there an example/documentation?


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

Jan 27 '06 #3
d

<Al************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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?
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)
Thank you.


dave
Jan 27 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

60 posts views Thread by Fotios | last post: by
4 posts views Thread by jas | last post: by
11 posts views Thread by Jovo Mirkovic | last post: by
35 posts views Thread by RobG | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.