Jump to content

Recommended Posts

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

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?

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();
   |

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.