代码如下:
01 | <?php |
02 | /** |
03 | * 重定向浏览器到指定的 URL |
04 | * www.jbxue.com |
05 | * @param string $url 要重定向的 url |
06 | * @param int $delay 等待多少秒以后跳转 |
07 | * @param bool $js 指示是否返回用于跳转的 JavaScript 代码 |
08 | * @param bool $jsWrapped 指示返回 JavaScript 代码时是否使用 <mce:script type="text/javascript"><!-- |
09 | 标签进行包装 |
10 | * @param bool $return 指示是否返回生成的 JavaScript 代码 |
11 | */ |
12 | function redirect( $url , $delay = 0, $js = false, $jsWrapped = true, $return = false) |
13 | { |
14 | $delay = (int) $delay ; |
15 | if (! $js ) { |
16 | if (headers_sent() || $delay > 0) { |
17 | echo <<<EOT |
18 | <html> |
19 | <head> |
20 | <meta http-equiv= "refresh" content= "{$delay};URL={$url}" /> |
21 | </head> |
22 | </html> |
23 | EOT; |
24 | exit ; |
25 | } else { |
26 | header( "Location: {$url}" ); |
27 | exit ; |
28 | } |
29 | } |
30 | |
31 | $out = '' ; |
32 | if ( $jsWrapped ) { |
33 | $out .= '<script language="JavaScript" type="text/javascript">' ; |
34 | } |
35 | $url = rawurlencode( $url ); |
36 | if ( $delay > 0) { |
37 | $out .= "window.setTimeOut(function () { document.location='{$url}'; }, {$delay});" ; |
38 | } else { |
39 | $out .= "document.location='{$url}';" ; |
40 | } |
41 | if ( $jsWrapped ) { |
42 | $out .= ' |
43 | // --></mce:script>'; |
44 | } |
45 | |
46 | if ( $return ) { |
47 | return $out ; |
48 | } |
49 | |
50 | echo $out ; |
51 | exit ; |
52 | } |
53 | ?> |
>>> 您可能感兴趣的文章:
PHP 页面跳转的多种方法总结
页面跳转代码(php、asp、js多版本)
PHP Header 页面跳转注意事项
php实现页面跳转的别样方法
php实现页面跳转的几种方法
header跳转和include包含问题实例分析
联系客服