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; } } Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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(); | Quote Link to comment 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.... Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.