asterix222 Posted December 25, 2014 Share Posted December 25, 2014 Hi everybody I want to put this code (or something like that) in my index.php to redirect the iPhones etc. But where do I have to put it in? In the head or body?? And how can I call this function? Thanks a lot for helping a beginner! function ismobile(){ $useragent = $_SERVER[‘HTTP_USER_AGENT’]; // Standard vendor-model/version user agents if(preg_match(‘/^((ACER¦Alcatel¦AUDIOVOX¦BlackBerry¦CDM¦Ericsson¦LG\b¦LGE¦Motorola¦MOT¦NEC¦Nokia¦Panasonic¦QCI¦SAGEM¦SAMSUNG¦SEC¦Sanyo¦Sendo¦SHARP¦SIE¦SonyEricsson¦Telit¦Telit_mobile_Terminals¦TSM)[- ]?([^\/\s\_]+))(\/(\S+))?/’, $useragent)){ return true; }else{ return false; } } Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/ Share on other sites More sharing options...
asterix222 Posted December 25, 2014 Author Share Posted December 25, 2014 I tried also this one: <body> <?php if(strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'Android') || strstr($_SERVER['HTTP_USER_AGENT'], 'BlackBerry')) { header('Location: http://www.google.com'); exit(); } ?> The iMac works, but the iPhone is grey. Where do I have to put it corretly? Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500632 Share on other sites More sharing options...
hansford Posted December 25, 2014 Share Posted December 25, 2014 I can only direct you to other resources http://detectmobilebrowsers.com/ Maybe others can chime in on tested and reliable resources. Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500639 Share on other sites More sharing options...
asterix222 Posted December 26, 2014 Author Share Posted December 26, 2014 Thanks a lot, that I saw and tried also. But I can't figure out where I have to put it in my code. Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500676 Share on other sites More sharing options...
ginerjm Posted December 26, 2014 Share Posted December 26, 2014 What you have posted looks just fine to me. If you meet those conditions you go to google.com. What ELSE are you trying to do here? Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500683 Share on other sites More sharing options...
asterix222 Posted December 26, 2014 Author Share Posted December 26, 2014 The problem is, that the screen from the iPhone is grey and doesn't go to google (which I inserted as a test). Where do I have to put in the code? In the head or in the body or elsewhere? Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500753 Share on other sites More sharing options...
ginerjm Posted December 26, 2014 Share Posted December 26, 2014 Technically I think one would want to use JS for this kind of thing, but you could try this: if (stripos($_SERVER['HTTP_USER_AGENT'], 'iPhone') ===false && stripos($_SERVER['HTTP_USER_AGENT'], 'Android') === false && stripos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') ===false) { // go to non-mobile page using header call header("Location: desktophome.php"); exit(); } else { // go to Mobile page instead header('Location: mobilehome.php"); exit(); | Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500755 Share on other sites More sharing options...
asterix222 Posted December 27, 2014 Author Share Posted December 27, 2014 Thanks, but that doesn't work either. Also iMac got a blank screen.... Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500782 Share on other sites More sharing options...
ginerjm Posted December 27, 2014 Share Posted December 27, 2014 Do you have php error checking turned on? What "doesn't work"? Not a very clear explanation. Something has to happen. Put some echos in your code to check the progress, etc., and temporarily eliminate the headers and just show messages. Link to comment https://forums.phpfreaks.com/topic/293336-iphone-and-other-devices-redirect/#findComment-1500817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.