0

以下代码检测到 PC 浏览器并进行重定向。这是一个工作。但是,我希望有人帮助改变它以显示一些东西。

  <?

$webversion = "http://www.webversion.com";

$agent = $_SERVER['HTTP_USER_AGENT'];

if (preg_match("/window/i", $agent)) {
header( "Location: $webversion" ) ;
}

if (preg_match("/mac/i", $agent)) {
header( "Location: $webversion" ) ;
}

if (preg_match("/microsoft/i", $agent)) {
header( "Location: $webversion" ) ;
}

if (preg_match("/linux/i", $agent)) {
header( "Location: $webversion" ) ;
}
?>

我想要它喜欢

if(usingPC)
echo 'something';
else
echo 'somethingelse'
4

1 回答 1

0

您将创建一个函数来封装上面的测试

function usingPC(){
      return preg_match("/window/i", $_SERVER['HTTP_USER_AGENT']);
}

要使用它,您必须将代码调整为:

if(usingPC())
    echo 'something';
else
    echo 'somethingelse'
于 2013-06-16T05:42:59.303 回答