0

我有一个包含变量的 URL,我希望该变量确定要重定向到的页面。我曾尝试在 Switch 语句中使用 Meta-redirect,但它不起作用。我做错了什么?

<?php
setcookie("affiliate", $_GET['a'], time()+31536000);
?>

<!DOCTYPE html>

<html>
<body>

<?php
switch($_GET['p'])
{
case"h": 
echo "<meta http-equiv="refresh" content="1; url=website/">";
echo "redirecting in 1 second";
echo "if this page does not redirect <a href="website/">click here.</a>";
  break;

case"w":
echo "<meta http-equiv="refresh" content="1; url=website/watches.html">";
echo "redirecting in 1 second";
echo "if this page does not redirect <a href="website/watches.html">click here.</a>";
  break;

case"sf":
echo "<meta http-equiv="refresh" content="1; url=website/watches/solar-flare.html">";
echo "redirecting in 1 second";
echo "if this page does not redirect <a href="website/watches/solar-flare.html">click here.</a>";
  break;

default:
echo "incorrect page option";
}
?>

</body>
</html> 

谢谢 :)

克里斯

4

2 回答 2

0

使用header功能:

header('Location: index.php');

或者

header('Location: http://google.com');

而不是打印元标记。

注意:header必须在打印页面上的任何内容之前使用该功能。因此,我建议您将开关移动到代码的顶部。

于 2013-10-12T07:23:06.053 回答
0

您可以refresh=X;url=Y在 X 秒后使用标头进行重定向:

<?php
setcookie("affiliate", $_GET['a'], time()+31536000);

switch($_GET['p']) {
    case"h": 
        header("refresh:5;url=website/"); 
        $body = "redirecting in 1 second<br />" . "if this page does not redirect <a href=\"website/\">click here.</a>";
        break;

    case"w":
        header("refresh:5;url=website/watches.html"); 
        $body = "redirecting in 1 second<br />" . "if this page does not redirect <a href=\"website/watches.html\">click here.</a>";
        break;

    case"sf":
        header("refresh:5;url=website/watches/solar-flare.html"); 
        $body = "redirecting in 1 second<br />" . "if this page does not redirect <a href=\"website/watches/solar-flare.html\">click here.</a>";
        break;

    default:
        $body = "incorrect page option";
}
?>

<!DOCTYPE html>

<html>
<body>

    <?= $body ?>

</body>
</html> 
于 2013-10-12T08:13:18.503 回答