我制作了一个如下所列的重定向脚本...无论传递什么 p 值,即使有效,它也会被重定向到 default.htm 页面...本质上它是跳过 if/else 部分并始终转到别的。
php header 函数有什么特别之处吗?它忽略了条件语句?
<?php
/*
Use the following link format:
<a href="goto.php?p=XXXXXX">XXXXXX</a>
*/
$p = $_GET['p'];
$link = array(
/*Links*/
'link1'=>'/link1.htm',
'link2'=>'/link2.htm',
);
/*Send Headers*/
header('Content-Type: text/html; charset=utf-8');
header('X-Robots-Tag: noindex, nofollow, noarchive', true);
if (in_array($p, $link))
{
header('Location: '.$link[$p]); // Valid p
}
else
{
header('Location: /default.htm'); // Invalid p
}
exit();
?>