Author |
php guru needed - browser detection script |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
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 |
|
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
hmm it worked. How strange?!?
Maybe its my host. I have another I will try it with.
[addsig] |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
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");
}
?>
[addsig] |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
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");
}
?>
|
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
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...
|
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
Thanks DSF - I will try it on my .com webhost. Hopefully it will work |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
no problem
Good luck
|
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
arrrggghh it still doesn't work. Internet expl & my mobile both get forwarded to /mob directory:
<?
$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");
}
?>
[addsig] |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
wtf is going on?
Do you think it may be the php version on my server?
[addsig] |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
hmm....
What version of PHP is installed ? (if you don't know make a file with <? phpinfo(); ?>
try:
<?
$ok = "http://www.wapchimp.com/mob";
$bad = "http://www.wapchimp.com/web";
$BrowserSplit = explode("/", $HTTP_SERVER_VARS["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-23 03:12 ] |
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
It worked
Thank you
[addsig] |
DSF Joined: Dec 01, 2002 Posts: > 500 From: Romania PM, WWW
|
Quote:
|
On 2004-09-23 12:56:08, wapchimp wrote:
It worked
Thank you
|
|
no problem.
which one? the last?
|
wapchimp Joined: Jun 09, 2002 Posts: > 500 From: Land of the chimps PM, WWW
|
Yes the last one
I had 4.2.2 php
_________________
(your resident wap guru)
wapchimp.com
[ This Message was edited by: wapchimp on 2004-09-23 17:13 ] |
|