站长论坛
标题:
PHP经典的地址重定向函数
[打印本页]
作者:
superadmin
时间:
2007-12-18 13:19
标题:
PHP经典的地址重定向函数
function redirect($url) {
$protocol = $_SERVER['HTTPS'] == 'off' ? 'http://' : 'https://';
$hostspec = $_SERVER['SERVER_NAME'];
$dir_name = str_replace('\\', '/', dirname($_SERVER['PHP_SELF']));
if ($dir_name != '/') $dir_name .= '/';
if ($url{0} == '/') $redirect = $protocol . $hostspec . $url;
elseif (strstr($url, '://')) $redirect = $url;
else $redirect = $protocol . $hostspec . $dir_name . $url;
header("Location: $redirect");
exit;
}
//本函数适合于一般的地址转换!
欢迎光临 站长论坛 (http://www.tzlink.com/bbs/)
Powered by Discuz! X3.2