How can I use PHP to redirect IE users to a certai

2019-07-29 15:40发布

问题:

Possible Duplicate:
Redirecting to a new page when a user is using Internet Explorer

I'm working on a version of my website which renders properly in Internet Explorer; what would a PHP script, which automatically redirects users with an IE user agent to (for example) /index-ie.php, look like?

回答1:

Try

PHP have function $_SERVER['HTTP_USER_AGENT'] used to identify browser

 if(using_ie())
 {
   //redirect
 }
function using_ie() 
    { 
        $u_agent = $_SERVER['HTTP_USER_AGENT']; 
        $ub = False; 
        if(preg_match('/MSIE/i',$u_agent)) 
        { 
            $ub = True; 
        } 

        return $ub; 
    } 


回答2:

you can use strpos function to search the string for MSIE. ex,

if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
  header('Location: /index-ie.php');
  exit;
}


回答3:

Get all information about user browser --

<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
print_r($browser);
?>


回答4:

Try this :

function using_ie()
{
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $ub = False;
    if(preg_match('/MSIE/i',$u_agent))
    {
        $ub = True;
    }

    return $ub;
}

You will get value 1 if it is internet explorer.



回答5:

Hope this works:

     $user_agent = $_SERVER['HTTP_USER_AGENT'];

     if(preg_match('MSIE',$user_agent))
     {
       header('Location: https://'. $_SERVER['HTTP_HOST'] .'/index.php']);
     }