Author |
php guru needed - browser detection script |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
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 ] |
|
mwright Joined: Jun 21, 2003 Posts: > 500 From: UK PM |
Try hotscripts.com. In the php section they have a couple of detection scripts.
This message was posted from a T610 |
Cycovision Joined: Nov 30, 2003 Posts: > 500 From: England PM, WWW
|
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  |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
Thanks Yeah just divert ie ane netscape
And allow the rest through
This message was posted from a T610 |
Cycovision Joined: Nov 30, 2003 Posts: > 500 From: England PM, WWW
|
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. |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
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 ] |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
Thanks i wil try it
This message was posted from a T610 |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
Np. Have u tried it?
This message was posted from a T300 |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
Not yet. Im busy working :-(
This message was posted from a T610 |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
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
[addsig] |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
my example works 100% (as allready, perhaps, you know)
Complete example
<?
$ok = "the url to the ok page";
$bad = "the url to the wrong browser page";
$BrowserSplit = explode("/", $HTTP_USER_AGENT);
$Machine = $BrowserSplit[0];
if($Machine == "Opera" || $Machine == "Mozilla") {
header("location: $bad");
}
else {
header("location: $ok");
}
?>
_________________
http://xpc.go.ro/wap/ WEB
http://xpc.go.ro/wap.wml WML/WAP
[ This Message was edited by: DSF on 2004-09-20 20:28 ] |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
lol - thanks I will try it again  |
Valentiner Joined: Aug 23, 2004 Posts: 152 PM |
you can also use the stristr function, which I belive it's best.
search for mozilla |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
nope this still re-directs internet explorer to my 'good' page ?!?
<?
$ok = "http://www.wapchimp.com/mob";
$bad = "http://www.wapchimp.com/web";
$BrowserSplit = explode("/", $HTTP_USER_AGENT);
$Machine = $BrowserSplit[0];
if($Machine == "Opera" || $Machine == "Mozilla") {
header("location: $bad");
}
else {
header("location: $ok");
}
?>
[ This Message was edited by: wapchimp on 2004-09-21 00:43 ] |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
It cannot be possible.
check:
http://weblinx.prezenta-web.com/wap/detect.php
I've used exactly the code that you've gived in the last post.
Check it first with your mobile, than with IE or Opera
Donno, it must work on your server, too!
_________________
http://xpc.go.ro/wap/ WEB
http://xpc.go.ro/wap.wml WML/WAP
[ This Message was edited by: DSF on 2004-09-21 01:10 ] |
|