从php中的URL重定向

时间:2011-04-18 17:01:48

标签: php redirect header

我想知道如何从php获取原始网址

例如:

example.php
<?php

header('location:test.php');

?>

我想从example.php获得test.php。

3 个答案:

答案 0 :(得分:2)

example.php
<?php

header('location:' . $_SERVER['HTTP_REFERER']);

?>

这应该可以正常工作。

答案 1 :(得分:0)

有一些延迟的重定向说在等待5秒后。

function js_redirect($url, $seconds)
{
    echo "<script language=\"JavaScript\">\n";
    echo "<!-- hide code from displaying on browsers with JS turned off\n\n";
    echo "function redirect() {\n";
    echo "window.parent.location = \"" . $url . "\";\n";
    echo "}\n\n";
    echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n";
    echo "-->\n";
    echo "</script>\n";

    return true;
}

js_redirect("http://www.exapmle.com",5); // Redirect after 5 sec

答案 2 :(得分:0)

你忘了使用

ob_start();

在你的第一个代码中:D

在其他地方你可以使用js,例如:

echo 'javascript:window.location="http://example.com";';