Esato

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

Previous  12
Author php guru needed - browser detection script
wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-21 11:49
Reply with quoteEdit/Delete This PostPrint this post
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
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-21 14:22
Reply with quoteEdit/Delete This PostPrint this post
hmm it worked. How strange?!?

Maybe its my host. I have another I will try it with. [addsig]
wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-21 14:30
Reply with quoteEdit/Delete This PostPrint this post
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
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2004-09-21 16:14
Reply with quoteEdit/Delete This PostPrint this post
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
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2004-09-21 16:19
Reply with quoteEdit/Delete This PostPrint this post
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
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-21 18:52
Reply with quoteEdit/Delete This PostPrint this post
Thanks DSF - I will try it on my .com webhost. Hopefully it will work
DSF
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2004-09-22 23:38
Reply with quoteEdit/Delete This PostPrint this post
no problem

Good luck
wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-23 02:51
Reply with quoteEdit/Delete This PostPrint this post
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
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-23 03:00
Reply with quoteEdit/Delete This PostPrint this post
wtf is going on?

Do you think it may be the php version on my server? [addsig]
DSF
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2004-09-23 04:11
Reply with quoteEdit/Delete This PostPrint this post
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
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-23 12:56
Reply with quoteEdit/Delete This PostPrint this post
It worked

Thank you [addsig]
DSF
R520
Joined: Dec 01, 2002
Posts: > 500
From: Romania
PM, WWW
Posted: 2004-09-23 13:56
Reply with quoteEdit/Delete This PostPrint this post
Quote:

On 2004-09-23 12:56:08, wapchimp wrote:
It worked

Thank you



no problem.
which one? the last?
wapchimp
C905 Silver
Joined: Jun 09, 2002
Posts: > 500
From: Land of the chimps
PM, WWW
Posted: 2004-09-23 18:13
Reply with quoteEdit/Delete This PostPrint this post
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 ]
Access the forum with a mobile phone via esato.mobi