[PHP] php URL安全跳转 →→→→→进入此内容的聊天室

来自 , 2020-03-12, 写在 PHP, 查看 106 次.
URL http://www.code666.cn/view/366f0bc7
  1. function safe_redirect($url, $exit=true) {
  2.  
  3.     // Only use the header redirection if headers are not already sent
  4.     if (!headers_sent()){
  5.  
  6.         header('HTTP/1.1 301 Moved Permanently');
  7.         header('Location: ' . $url);
  8.  
  9.         // Optional workaround for an IE bug (thanks Olav)
  10.         header("Connection: close");
  11.     }
  12.  
  13.     // HTML/JS Fallback:
  14.     // If the header redirection did not work, try to use various methods other methods
  15.  
  16.     print '<html>';
  17.     print '<head><title>Redirecting you...</title>';
  18.     print '<meta http-equiv="Refresh" content="0;url='.$url.'" />';
  19.     print '</head>';
  20.     print '<body onload="location.replace(\\''.$url.'\\')">';
  21.  
  22.     // If the javascript and meta redirect did not work,
  23.     // the user can still click this link
  24.     print 'You should be redirected to this URL:<br />';
  25.     print "<a href="$url">$url</a><br /><br />";
  26.  
  27.     print 'If you are not, please click on the link above.<br />';    
  28.  
  29.     print '</body>';
  30.     print '</html>';
  31.  
  32.     // Stop the script here (optional)
  33.     if ($exit) exit;
  34. }
  35. //该片段来自于http://yuncode.net
  36.  

回复 "php URL安全跳转"

这儿你可以回复上面这条便签

captcha