Esato

Forum > General discussions > General > php guru needed - browser detection script

12  Next
Author php guru needed - browser detection script
wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2003-12-14 02:12
Reply with quoteEdit/Delete This PostPrint this post
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
T610
Joined: Jun 21, 2003
Posts: > 500
From: UK
PM
Posted: 2003-12-14 02:18
Reply with quoteEdit/Delete This PostPrint this post
Try hotscripts.com. In the php section they have a couple of detection scripts.

This message was posted from a T610

Cycovision
P990
Joined: Nov 30, 2003
Posts: > 500
From: England
PM, WWW
Posted: 2003-12-14 02:32
Reply with quoteEdit/Delete This PostPrint this post
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
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2003-12-14 02:58
Reply with quoteEdit/Delete This PostPrint this post
Thanks Yeah just divert ie ane netscape And allow the rest through

This message was posted from a T610

Cycovision
P990
Joined: Nov 30, 2003
Posts: > 500
From: England
PM, WWW
Posted: 2003-12-14 16:57
Reply with quoteEdit/Delete This PostPrint this post
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
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2003-12-14 18:51
Reply with quoteEdit/Delete This PostPrint this post
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
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2003-12-14 19:48
Reply with quoteEdit/Delete This PostPrint this post
Thanks i wil try it

This message was posted from a T610

DSF
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2003-12-17 19:35
Reply with quoteEdit/Delete This PostPrint this post
Np. Have u tried it?

This message was posted from a T300

wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2003-12-17 19:44
Reply with quoteEdit/Delete This PostPrint this post
Not yet. Im busy working :-(

This message was posted from a T610

wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-07-07 22:07
Reply with quoteEdit/Delete This PostPrint this post
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
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2004-09-20 21:17
Reply with quoteEdit/Delete This PostPrint this post
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
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-20 21:52
Reply with quoteEdit/Delete This PostPrint this post
lol - thanks I will try it again
Valentiner
S700
Joined: Aug 23, 2004
Posts: 152
PM
Posted: 2004-09-20 22:15
Reply with quoteEdit/Delete This PostPrint this post
you can also use the stristr function, which I belive it's best.
search for mozilla
wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-21 01:43
Reply with quoteEdit/Delete This PostPrint this post
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
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2004-09-21 02:06
Reply with quoteEdit/Delete This PostPrint this post
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 ]
Access the forum with a mobile phone via esato.mobi