好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php的URL重定向函数

// URL重定向

function redirect($url, $time=0, $msg=”) {

//多行URL地址支持

$url = str_replace(array(“\n”, “\r”), ”, $url);

if ( empty($msg) )

$msg = “系统将在{$time}秒之后自动跳转到{$url}!”;

if (!headers_sent()) {

// redirect

if (0 === $time) {

header(‘Location: ‘ . $url);

} else {

header(“refresh:{$time};url={$url}”);

echo($msg);

}

exit();

} else {

$str = “<meta http-equiv=’Refresh’ content='{$time};URL={$url}’>”;

if ($time != 0)

$str .= $msg;

exit($str);

}

}

 

//url重定向2
function redirect($url) {

echo “<script>”.
“function redirect() {window.location.replace(‘$url’);}\n”.
“setTimeout(‘redirect();’, 1000);\n”.
“</script>”;
exit();

}

 

查看更多关于php的URL重定向函数的详细内容...

  阅读:1488次