>
New Topic
>
Reply<
Esato Forum Index
>
General discussions >
General
> php guru needed - browser detection script
Bookmark topic
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 ]
--
Posted: 2004-09-20 21:17:16
Edit :
Quote
lol - thanks I will try it again
--
Posted: 2004-09-20 21:52:49
Edit :
Quote
you can also use the stristr function, which I belive it's best.
search for mozilla
--
Posted: 2004-09-20 22:15:06
Edit :
Quote
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 ]
--
Posted: 2004-09-21 01:43:20
Edit :
Quote
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 ]
--
Posted: 2004-09-21 02:06:48
Edit :
Quote
Thanks. I have tested it via wap and opera on my mobile. So far so good. Just need to test with internet explorer and firefox
This message was posted from a Nokia
--
Posted: 2004-09-21 11:49:26
Edit :
Quote
hmm it worked. How strange?!?
Maybe its my host. I have another I will try it with.
--
Posted: 2004-09-21 14:22:06
Edit :
Quote
This one works ok though?!?
<?php
$bad = "http://www.wapchimp.com/web";
$ok = "http://www.wapchimp.com/mob";
if($_SERVER['HTTP_USER_AGENT']=='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)') {
header("location: $bad");
} elseif($_SERVER['HTTP_USER_AGENT']=='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1') {
header("location: $bad");
} elseif($_SERVER['HTTP_USER_AGENT']=='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)') {
header("location: $bad");
} else {
header("location: $ok");
}
?>
--
Posted: 2004-09-21 14:30:15
Edit :
Quote
no, it's not good... because there are many versions of Mozilla and many doesn't match with your code....
Source code of 'detection.php'
<?
$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");
}
?>
--
Posted: 2004-09-21 16:14:04
Edit :
Quote
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)
and there are many many more....
$Machine detects only the first string from $HTTP_USER_AGENT, Mozilla in this case...
Hope i was clear...
--
Posted: 2004-09-21 16:19:05
Edit :
Quote
New Topic
Reply