為你詳細(xì)講解PHP重定向代碼的具體實(shí)現(xiàn)功能
作者:佚名
我們?yōu)榇蠹曳钌系氖荘HP重定向代碼,希望大家能夠收藏。作為以后編寫代碼時(shí)的參考和學(xué)習(xí)對(duì)象。
PHP語言是一個(gè)比較常用的功能強(qiáng)大的計(jì)算機(jī)語言。我們這次為大家編寫的這個(gè)PHP重定向代碼的功能很完善,可以很好地定制轉(zhuǎn)跳。#t#
PHP重定向代碼:
- < ?php
- /**
- * 重定向?yàn)g覽器到指定的 URL
- *
- * @param string $url 要重定向的 url
- * @param int $delay 等待多少秒以后跳轉(zhuǎn)
- * @param bool $js 指示是否返回用于跳轉(zhuǎn)的 JavaScript 代碼
- * @param bool $jsWrapped 指示返回
JavaScript 代碼時(shí)是否使用 < script> 標(biāo)簽進(jìn)行包裝 - * @param bool $return 指示是否返回生成的 JavaScript 代碼
- */
- function redirect($url, $delay = 0,
$js = false, $jsWrapped = true, $return = false) - {
- $delay = (int)$delay;
- if (!$js) {
- if (headers_sent() || $delay > 0) {
- echo < < < EOT
- < html>
- < head>
- < meta http-equiv="refresh"
content="{$delay};URL={$url}" /> - < /head>
- < /html>
- EOT;
- exit;
- } else {
- header("Location: {$url}");
- exit;
- }
- }
- $out = '';
- if ($jsWrapped) {
- $out .= '< script language="
JavaScript" type="text/javascript">'; - }
- $url = rawurlencode($url);
- if ($delay > 0) {
- $out .= "window.setTimeOut(function
() { document.location='{$url}'; }, {$delay});"; - } else {
- $out .= "document.location='{$url}';";
- }
- if ($jsWrapped) {
- $out .= '< /script>';
- }
- if ($return) {
- return $out;
- }
- echo $out;
- exit;
- }
- ?>
希望通過上見介紹的這段PHP重定向代碼示例,大家能學(xué)到更多的知識(shí)。
責(zé)任編輯:曹凱
來源:
網(wǎng)易博客