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

2019-07-29 15:18发布

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?

5条回答
\"骚年 ilove
2楼-- · 2019-07-29 15:54

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.

查看更多
混吃等死
3楼-- · 2019-07-29 15:57

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; 
    } 
查看更多
4楼-- · 2019-07-29 16:04

Hope this works:

     $user_agent = $_SERVER['HTTP_USER_AGENT'];

     if(preg_match('MSIE',$user_agent))
     {
       header('Location: https://'. $_SERVER['HTTP_HOST'] .'/index.php']);
     }
查看更多
虎瘦雄心在
5楼-- · 2019-07-29 16:07

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;
}
查看更多
孤傲高冷的网名
6楼-- · 2019-07-29 16:10

Get all information about user browser --

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

$browser = get_browser(null, true);
print_r($browser);
?>
查看更多
登录 后发表回答