开发者

Get redirected from URL in php

开发者 https://www.devze.com 2023-02-27 00:31 出处:网络
I want to know how to get the original URL from php For开发者_开发百科 example: example.php <?php

I want to know how to get the original URL from php

For开发者_开发百科 example:

example.php
<?php

header('location:test.php');

?>

I want to get test.php from example.php.


example.php
<?php

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

?>

This should work fine.


Redirection with some delay say after 5 sec wait.

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


you forget to use

ob_start();

in first of your code :D

elsewhere you can use js in this case , for example :

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号