How to Enable My Website for Mobile Version

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pirontech
Forum Commoner
Posts: 29
Joined: Wed Oct 28, 2009 5:31 am

How to Enable My Website for Mobile Version

Post by Pirontech »

Hi All,

i am developing a site (www.flexiguru.com) now i want to run this site on mobiles, i know how to design the website for the MObile.

Use Low CSS and Less Images and Layout shoud be 320*264.

but i dont know how to dedect that the website opened in the mobile.

i have uploaded my website bt creating a subdomain www.mobile.flexiguru.com.

But user type Only www.flexiguru.com on his mobile only and automaticaly user redirect to the subdomain which have the Mobile Designed Pages i mean user must redirect on www.mobile.flexiguru.com

Please help me..................

Thnx in Advance...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How to Enable My Website for Mobile Version

Post by pickle »

Check the user-agent. This can be done in PHP, Javascript, or possibly even .htaccess.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Pirontech
Forum Commoner
Posts: 29
Joined: Wed Oct 28, 2009 5:31 am

Re: How to Enable My Website for Mobile Version

Post by Pirontech »

Thanks

Can you please explain me in detail so that i can complete the task....
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How to Enable My Website for Mobile Version

Post by John Cartwright »

You'll have to collect a list of mobile user agents, and perhaps they all share the keyword "mobile" or something similiar. In that case, it would involve

if() + $_SERVER['HTTP_USER_AGENT'] + strpos() for "mobile"
Pirontech
Forum Commoner
Posts: 29
Joined: Wed Oct 28, 2009 5:31 am

Re: How to Enable My Website for Mobile Version

Post by Pirontech »

have u done the task recentaly, if yes please share teh code...


Thanks,

Dhiraj Kr.
priyanka123
Forum Newbie
Posts: 1
Joined: Mon Apr 26, 2010 5:16 am

Re: How to Enable My Website for Mobile Version

Post by priyanka123 »

Testing
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How to Enable My Website for Mobile Version

Post by John Cartwright »

Pirontech wrote:have u done the task recentaly, if yes please share teh code...


Thanks,

Dhiraj Kr.
No. Why don't you try posting what you have tried, and we will help you from there.
abushahin
Forum Commoner
Posts: 42
Joined: Wed Nov 25, 2009 12:35 pm
Location: london

Re: How to Enable My Website for Mobile Version

Post by abushahin »

Ok here you go, this works with alot of mobile user agents feel free to add more later known mobile user agents, if you do find them then please post here so that we can also add to our array.

Code: Select all

<?php
 
$mobile_browser = '0';
 
if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|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.mobile.site.com");
exit;
}
else {
   header("Location: http://www.site.com");
}   
 
?>
This is something I picked up a while ago from the web.
Pirontech
Forum Commoner
Posts: 29
Joined: Wed Oct 28, 2009 5:31 am

Re: How to Enable My Website for Mobile Version

Post by Pirontech »

Ya Sure i will post if i find any thing extra for MObiles
Post Reply