PHP url redirection (page jump) code

WBOY
Release: 2016-07-25 08:59:49
Original
1528 people have browsed it
Let me introduce to you a relatively complete URL redirection and page jump code. Friends in need can refer to it.

The code is as follows:

<?php   
 /**   
  * 重定向浏览器到指定的 URL   
  * bbs.it-home.org
  * @param string $url 要重定向的 url   
  * @param int $delay 等待多少秒以后跳转   
  * @param bool $js 指示是否返回用于跳转的 JavaScript 代码   
  * @param bool $jsWrapped 指示返回 JavaScript 代码时是否使用 <mce:script type="text/javascript"><!-- 
  标签进行包装   
  * @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 .= '  
 // --></mce:script>';   
  }   
   
  if ($return) {   
   return $out;   
  }   
   
  echo $out;   
  exit;   
 }    
?>
Copy after login

>>>> Articles you may be interested in: Summary of various methods of PHP page jump Page jump code (php, asp, js multiple versions) PHP Header page jump precautions A different way to implement page jump in php Several ways to implement page jump in php Header jump and include inclusion problem example analysis



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!