>
New Topic
>
Reply<
Esato Forum Index
>
General discussions >
General
> php guru needed - browser detection script
Bookmark topic
any php masters here??!?
So far I have this - I know where to put the unwanted browser user strings in - I can get it to work, but can it be modified to only re-direct say IE & Netscape & allow all o ther browser without needing to put EVERY mobile phone user agent in ?
$ok = "the url to the ok page";
$bad = "the url to the wrong browser page";
if($_SERVER['USER_AGENT']=='name of the mobile browser') {
header("location: $ok");
} else {
header("location: $bad");
}
?>
Thanks
_________________
wapchimp.com
The BEST & ONLY retro xhtml wap site.
[ This Message was edited by: orangeman on 2003-12-14 01:12 ]
--
Posted: 2003-12-14 02:12:00
Edit :
Quote
Try hotscripts.com. In the php section they have a couple of detection scripts.
This message was posted from a T610
--
Posted: 2003-12-14 02:18:22
Edit :
Quote
I can't remember the exact syntax, but you should be able to use a logical 'or', e.g. in pseudo code
if($_SERVER['USER_AGENT']=='ieexplorer') || if($_SERVER['USER_AGENT']=='netscape');
--redirect for these browsers
ELSE
--redirect elsewhere
Sorry for the s***y example, I'll dig my PHP book out and get a working example for you!
Hope that's what you're trying to do anyway
--
Posted: 2003-12-14 02:32:33
Edit :
Quote
Thanks Yeah just divert ie ane netscape
And allow the rest through
This message was posted from a T610
--
Posted: 2003-12-14 02:58:12
Edit :
Quote
I was nearly right! Structure of the 'If' statement should be:
$ok = "the url to the ok page";
$bad = "the url to the wrong browser page";
if($_SERVER['USER_AGENT']=='iexplorer' || $_SERVER['USER_AGENT')]=='netscape') {
header("location: $bad");
} else {
header("location: $ok");
}
I'd double check the browser type returns from the $_SERVER['USER_AGENT'] variable to make sure that they are actually 'iexplorer' and 'netscape'. Should be able to find the info on google or one of the big php sites (www.php.org)? You might have to add another 'or' to check for 'mozilla', too.
--
Posted: 2003-12-14 16:57:08
Edit :
Quote
Orangeman try this:
$Machine will detect, for ex: if browser is: SonyEricssonT610/R101 Profile/MIDP-1.0 Configuration/CLDC-1.0 UP.Link/5.1.1a, just SonyEricssonT610. If SonyEricssonT610/R101 Profile/MIDP-1.0 Configuration/CLDC-1.0 then $Machine will detect again SonyEricssonT610 ... Same with T300 and Mozilla ...
Hope this helps!
BTW: i used some of code in my wapsite for detection from wich phone was posted the message (see "Guestbook")
$ok = "the url to the ok page";
$bad = "the url to the wrong browser page";
$Browser = $HTTP_USER_AGENT;
$BrowserSplit = explode("/", $HTTP_USER_AGENT);
$Machine = $BrowserSplit[0];
if($Machine == "Opera" || $Machine == "Mozilla") {
header("location: $bad");
}
else {
header("location: $ok");
}
_________________
website:
http://xpc.go.ro (Romanian)
wapsite:
http://xpc.go.ro/wap.wml (English)
--
We love
[ This Message was edited by: DSF on 2003-12-14 17:57 ]
[ This Message was edited by: DSF on 2003-12-14 18:07 ]
--
Posted: 2003-12-14 18:51:05
Edit :
Quote
Thanks i wil try it
This message was posted from a T610
--
Posted: 2003-12-14 19:48:23
Edit :
Quote
Np. Have u tried it?
This message was posted from a T300
--
Posted: 2003-12-17 19:35:39
Edit :
Quote
Not yet. Im busy working :-(
This message was posted from a T610
--
Posted: 2003-12-17 19:44:29
Edit :
Quote
Just found this in my bookmarks - I'm gunna try it as Ive had about 6 attempts so far, none of which have worked. I love php
--
Posted: 2004-07-07 22:07:30
Edit :
Quote
New Topic
Reply