Mobile site

Discussion in 'PHP' started by roice, Jun 22, 2010.

  1. #1
    Hello,
    I built a mobile version for my website.
    Does anyone know what is the PHP code that I nned to put in my INDEX file so if the visitor slide into my website with his phone he will automateclly redirct to mobile sub domain -> m.mysite.com ?

    Thank you in advance,
    Roi
     
    roice, Jun 22, 2010 IP
  2. SEbasic

    SEbasic Peon

    Messages:
    6,317
    Likes Received:
    318
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What platform have you built the main site on?

    You'll have to check for the browser user agent (or screen res) & based on that send the user to the appropriate version of the site.

    If you're using a CMS like WordPress there are plenty of plugins out there that do that kind of thing, otherwise you'll be looking for a relatively complicated solution to do what you're looking for - For instance you'd need a bank of known user agents or screen sizes to check for & keep updated.
     
    SEbasic, Jun 22, 2010 IP
  3. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi SEbasic,
    I'm writting in PHP. I build the all website.
     
    roice, Jun 22, 2010 IP
  4. morency

    morency Well-Known Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #4
    This a easy function what I use.

    
    
    $user_browser = $_SERVER["HTTP_USER_AGENT"];
    
    	function check_for_mobile($user_browser){
    
    		$mobile_browsers = array( // update this list if you need
    						'2.0 MMP',
    					//	'Mozilla',
    					//	'Opera',
    					//	'Opera',
    						'240x320',
    						'AvantGo',
    						'BlackBerry',
    						'Blazer',
    						'Cellphone',
    						'Danger',
    						'DoCoMo',
    						'Elaine/3.0',
    						//'EudoraWeb',
    						'hiptop',
    						'IEMobile',
    						'KYOCERA/WX310K',
    						'LG/U990',
    						'MIDP-2.0',
    						'MMEF20',
    						'MOT-V',
    						'NetFront',
    						'Newt',
    						'Nintendo Wii',
    						'Nitro', // Nintendo DS
    						'Opera Mini',
    						'Palm',
    						'Playstation Portable',
    						'portalmmm',
    						'Proxinet',
    						'ProxiNet',
    						'Small',
    						'Symbian OS',
    						'SymbianOS',
    						'TS21i-10',
    						'UP.Browser',
    						'UP.Link',
    						'Windows CE',
    						//'WinWAP',
    						'Nokia',
    						'SHARP-TQ-GX10',
    						'Audiovox',
    						'Benq-Siemens',
    						'BlackBerry',
    						'Boost',
    						'Boost Mobile',
    						'Cingular',
    						'Eten glofish',
    						'Firefly Phone',
    						'Handspring',
    						'Hiptop2',
    						'Hitachi',
    						'Hp',
    						'HP',
    						'HTC',
    						'I-mate',
    						'Kyocera',
    						'LG',
    						'Mitsubishi',
    						'Mitsubishi Trium',
    						'Motorola',
    						'NEC',
    						'Nec',
    						'Palm',
    						'Panasonic',
    						'Pantech',
    						'Philips',
    						'Sagem',
    						'Samsung',
    						'Sanyo',
    						'SonyEricsson',
    						'Sharp',
    						'Sidekick',
    						'Siemens',
    						'Sprint',
    						'T-mobile',
    						'Toshiba',
    						'Treo',
    						'UTStarcom',
    						'Utstarcom',
    						'Verizon Wireless',
    						'VK'
    					);
    
    
    
    		foreach ($mobile_browsers as $browser) {
    			if (strstr($user_browser, $browser)) {
    				return true;
    			}
    		}
    		return false;
    
    	}
    
    
    //USAGE:
    	if(check_for_mobile($user_browser)){
    
    ///looks like a mobile ... bla bla
    
    }
    
    else {
    /// not a mobile device.?!
    }
    
    
    
    PHP:
    OR
    You can make this requests
    
    $p1 = $_SERVER["HTTP_X_WAP_PROFILE"];
    $p2 = $_SERVER["HTTP_PROFILE"];
    $p3=$_SERVER["HTTP_x"];
    
    
    PHP:
    one of this variable will return a adress like nds1.nds.nokia.com/uaprof/NE71-1r100.xml .
    But this work only if your visitor use default browser.
    If not (if they use Opera mini,UCWeb or other browsers) that HTTP headers will not return any info



    PS: Sorry for my english :-|
     
    Last edited: Jun 22, 2010
    morency, Jun 22, 2010 IP
  5. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks morency!
    I'm realy appreciate your help!

    Why do I need the last part in your code:
    $p1 = $_SERVER["HTTP_X_WAP_PROFILE"];
    $p2 = $_SERVER["HTTP_PROFILE"];
    $p3=$_SERVER["HTTP_x"];
    PHP:

    is it instead $user_browser = $_SERVER["HTTP_USER_AGENT"];
    ?
     
    roice, Jun 23, 2010 IP
  6. morency

    morency Well-Known Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #6
    this was just a ideea.

    
    $p1 = $_SERVER["HTTP_X_WAP_PROFILE"];
    $p2 = $_SERVER["HTTP_PROFILE"];
    $p3=$_SERVER["HTTP_x"];
    
    PHP:
    are just few varialbes from $_Server array .
    If any of this return a site address means that visitor is a "mobile" one.
     
    morency, Jun 23, 2010 IP
  7. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    and do I need to send p1, p2, p3 to function check_for_mobile?
    for example: if (check_for_mobile($p1)){

    ?
     
    roice, Jun 24, 2010 IP