I have a php based website that I want to redirect the user to a mobile version of specific pages but only for those URL's, there are certain urls I want to keep as is for features to work as they currently do.
I know you can set a rule in config.php that says
if(!defined('_MOBILE') && !defined('_ADMIN') && $_SESSION['DV'] != 'true' && $_REQUEST['code'] == '' && $converting != 'true') {
header("Location:".$config['MOBILE_URL'].$vinf);
exit;
}
But that will redirect on all pages if a mobile device is found, I just want to redirect for example if (mobile && location = "mysite/test"){//do redirect}
Any advice on how to go about this? Would a rule need to be set on each individual php page that the redirect must happen on rather than in a config.php file?
Thanks for the help.
EDIT:
When I comment out the following then the browser does not redirect the user when on a mobile device:
/*
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['base_url'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['IPHONE'] = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if (strpos($_SERVER['HTTP_USER_AGENT'],"iPad")) $config['IPHONE'] = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if (stripos($ua,"android")) $config['IPHONE'] = stripos($ua,"android");
if($config['IPHONE']) {
if(!defined('_MOBILE') && !defined('_ADMIN') && $_SESSION['DV'] != 'true' && $_REQUEST['code'] == '' && $converting != 'true') {
header("Location:".$config['MOBILE_URL'].$vinf);
exit;
}
}
}*/
Mobile Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
Using that it's quite easy to only display content for a mobile:
include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
// Check for any mobile device.
if ($detect->isMobile() && $_SERVER['REQUEST_URI'] == "YOUR_URL_HERE"){
header("Location:".$config['MOBILE_URL'].$vinf);
exit;
}
else
// other content
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.