best way to determine mobile device
-
Hi, What's the best way to determine the mobile device then redirect to the /mobile? Regards, Jassim
-
Hi, What's the best way to determine the mobile device then redirect to the /mobile? Regards, Jassim
As a start, read these, they should help you ... http://webdesignerwall.com/tutorials/css3-media-queries[^] http://webdesignerwall.com/tutorials/responsive-design-with-css3-media-queries[^] then, if necessary, do some Googling and further reading. [added] You could have accepted Graham's answer in the Web Dev forum
-
Hi, What's the best way to determine the mobile device then redirect to the /mobile? Regards, Jassim
Detecting if its a mobile device Please follow the above link. It looks good
-
Detecting if its a mobile device Please follow the above link. It looks good
Detecting if its a mobile device
Please follow the above link. It looks good
but how can I implement it? Do i have to put it in every page? is it possible to put it in one place for the entire application?
-
Detecting if its a mobile device
Please follow the above link. It looks good
but how can I implement it? Do i have to put it in every page? is it possible to put it in one place for the entire application?
You could do either one of the two. But I would suggest creating a generic php file with this piece of code in a method. Including that php file in every page and calling that method. EG: dection.php <-- contains the check + redirect Sample index.php:
-
Detecting if its a mobile device
Please follow the above link. It looks good
but how can I implement it? Do i have to put it in every page? is it possible to put it in one place for the entire application?
Put it in the initial page. That is the first page user would open. such as index page or login page. If it figured out that the client device is mobile save that information to session. As a matter of fact its not a big deal. you dont even need to remember whether it is a mobile device or not. But If the set of functions are different for mobile and pc then you can use the session variable to determine about which function to call. more over when it would redirect to page allocated for mobile do not put any link to those mobile page that redirect to pc pages
-
You could do either one of the two. But I would suggest creating a generic php file with this piece of code in a method. Including that php file in every page and calling that method. EG: dection.php <-- contains the check + redirect Sample index.php:
sorry but need more help plz that mentioned code will be placed in a separet file.. that's file.. but it will be between tage? right? then followed by the if($mobile === true)? so is the following code correct?:
<?php
function detect_mobile()
{
$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';$mobile\_browser = '0'; $agent = strtolower($\_SERVER\['HTTP\_USER\_AGENT'\]); if(preg\_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', $agent)) $mobile\_browser++; if((isset($\_SERVER\['HTTP\_ACCEPT'\])) and (strpos(strtolower($\_SERVER\['HTTP\_ACCEPT'\]),'application/vnd.wap.xhtml+xml') !== false)) $mobile\_browser++; if(isset($\_SERVER\['HTTP\_X\_WAP\_PROFILE'\])) $mobile\_browser++; if(isset($\_SERVER\['HTTP\_PROFILE'\])) $mobile\_browser++; $mobile\_ua = substr($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'
-
sorry but need more help plz that mentioned code will be placed in a separet file.. that's file.. but it will be between tage? right? then followed by the if($mobile === true)? so is the following code correct?:
<?php
function detect_mobile()
{
$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';$mobile\_browser = '0'; $agent = strtolower($\_SERVER\['HTTP\_USER\_AGENT'\]); if(preg\_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', $agent)) $mobile\_browser++; if((isset($\_SERVER\['HTTP\_ACCEPT'\])) and (strpos(strtolower($\_SERVER\['HTTP\_ACCEPT'\]),'application/vnd.wap.xhtml+xml') !== false)) $mobile\_browser++; if(isset($\_SERVER\['HTTP\_X\_WAP\_PROFILE'\])) $mobile\_browser++; if(isset($\_SERVER\['HTTP\_PROFILE'\])) $mobile\_browser++; $mobile\_ua = substr($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'
That would indeed work. If you put the entire function in the external php file and the code below in all files that need the check for mobile devices.
if (detect_mobile()) {
header('Location: blog');
}Please note though that the redirect that you put in you code would not work as is. You would need to replace the 'blog' part with a URL to the mobile site.
-
That would indeed work. If you put the entire function in the external php file and the code below in all files that need the check for mobile devices.
if (detect_mobile()) {
header('Location: blog');
}Please note though that the redirect that you put in you code would not work as is. You would need to replace the 'blog' part with a URL to the mobile site.
I am now getting this error:
Parse error: syntax error, unexpected T_VARIABLE in /home/jassimrahma/JassimRahma.com/detection.php on line 4
this is what I put in my index.php 1st line:
<?php
include_once('detection.php');
if (detect_mobile()) {
header('Location: http://m.jassimrahma.com');
}
?>and detection.php is here:
<?php
function detect_mobile()
{
$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';$mobile\_browser = '0'; $agent = strtolower($\_SERVER\['HTTP\_USER\_AGENT'\]); if(preg\_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', $agent)) $mobile\_browser++; if((isset($\_SERVER\['HTTP\_ACCEPT'\])) and (strpos(strtolower($\_SERVER\['HTTP\_ACCEPT'\]),'application/vnd.wap.xhtml+xml') !== false)) $mobile\_browser++; if(isset($\_SERVER\['HTTP\_X\_WAP\_PROFILE'\])) $mobile\_browser++; if(isset($\_SERVER\['HTTP\_PROFILE'\])) $mobile\_browser++; $mobile\_ua = substr($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-&#
-
That would indeed work. If you put the entire function in the external php file and the code below in all files that need the check for mobile devices.
if (detect_mobile()) {
header('Location: blog');
}Please note though that the redirect that you put in you code would not work as is. You would need to replace the 'blog' part with a URL to the mobile site.
Thanks I am using now this and very simple and works fine for me.. http://code.google.com/p/php-mobile-detect/[^]