简体   繁体   中英

how to identify a device and use a code for a pc device and a second code for mobile(ios or android)?

I'm trying to add a code (php, js, jquery with redirect page) that identify a pc, laptop or a mobile device and redirect a pc/laptop into a one page code and a second page code for a mobile.

Meaning the pc/laptop will have his code and the mobile will have a different code.

Am using the following option to detect mobile device and redirect to another page

<?php
$iphone = strpos($_SERVER['HTTP_USER_AGENT'], "iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'], "Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'], "webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'], "BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'], "iPod");

if ($iphone || $android || $palmpre || $ipod || $berry == true) {
header('Location: http://YOUR PAGE LINK/test/');
}
?>

this is the location of page to be redirect

 header('Location: http://YOUR PAGE LINK/test/');

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM