Wanted mobile detector code

Started on the old forum in December 2011 · view the original in the archive · old links redirect here

15 replies · 1,240 views · started 14 years ago · 1 min read

7 participants
zong11 Developer · 98 posts #1

WapMasters i want mobile detector code so that site should run only on mobile not on pc. Plzzzzz help

Always Help Needy Peoples !!!!!

zong11 Developer · 98 posts #3

how to use this code?????

Always Help Needy Peoples !!!!!

GumSlone Administrator Principal · 1,690 posts #4

zong11 wrote: how to use this code?????

require_once('mobile_device_detect.php');
$mobile = mobile_device_detect();
if($mobile == true)
{
echo 'Mobile phone user.';
}
else
{
echo 'PC user.';
}

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

irfiii Developer · 249 posts #5
<?php
//////GYSMS.com Browser Detection

$mobile_browser = '0';

if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wa p|phone)/i',
strtolower($_SERVER['HTTP_USER_AGENT']))){
$mobile_browser++;
}

if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or
((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
$mobile_browser++;
}

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird' ,'blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil',' play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda','xda-');

if(in_array($mobile_ua,$mobile_agents)){
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
$mobile_browser=0;
}

if($mobile_browser>0){

header("Location: http://www.yourmobilesite.com");
}
else{
header("Location: http://www.yoursite.com/notphone.php");

}

?>

Added after 2 minutes:

i am using on all my sites and working very well.. check demo at adcell.mobi from ur mob and pc

Free Web Hosting @HostersPoint.com php Hosting with Web Builder

Buy - Sell ADs ADMOLA ADs Network Monetize Your Site Traffic

GumSlone Administrator Principal · 1,690 posts #6

irfiii wrote: Added after 2 minutes:

i am using on all my sites and working very well.. check demo at adcell.mobi from ur mob and pc

the function by Andy Moore is more advanced, i would recommend you to use it instead of this code.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

arnage Lead · 811 posts #8

irfiii wrote:

<?php
//////GYSMS.com Browser Detection

$mobile_browser = '0';

if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wa p|phone)/i',
strtolower($_SERVER['HTTP_USER_AGENT']))){
$mobile_browser++;
}

if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or
((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){
$mobile_browser++;
}

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird' ,'blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil',' play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda','xda-');

if(in_array($mobile_ua,$mobile_agents)){
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
$mobile_browser++;
}
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
$mobile_browser=0;
}


if($mobile_browser>0){

header("Location: http://www.yourmobilesite.com");
}
else{
header("Location: http://www.yoursite.com/notphone.php");

}

?>

Added after 2 minutes:

i am using on all my sites and working very well.. check demo at adcell.mobi from ur mob and pc

Anyway if you using it or not, in this part needs to be a space between OperaMini:

if (strpos(strtolower($_SERVER['ALL_HTTP']),'Opera Mini')>0) { 
$mobile_browser++; 
}

And this i think is wrong because its alone in a string at position 0 in $_SERVER['HTTP_ACCEPT'].

//...
strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0)
//...

But i got an idea on mobile redirect. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arnage Lead · 811 posts #10

You were right, i have just read the code btb and didn't test it first. My mistake. Sorry.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
zong11 Developer · 98 posts #11

Thanks masters

Thanks masters for sharing codes but how to use that codes anyone plz help????

Always Help Needy Peoples !!!!!

arnage Lead · 811 posts #15

brentg wrote: anyone help please

In the script. 🤪

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
softwarefreak Senior · 349 posts #16

brentg wrote: anyone help please

Just change this habit of grabbing ready made things,Go thru some basic tutorials...That'd help you 🙂

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close