PHP后端如何实现跳转封装的最佳实践?
- 内容介绍
- 相关推荐
本文共计145个文字,预计阅读时间需要1分钟。
PHP后端封装跳转功能,内容如下:
php/** * 页面跳转封装 * @param $url 跳转地址 * @param $time 一段时间后跳转 */function app_redirect($url, $time=0, $msg='') { // 多行URL地址支持 $url=str_replace(array(\n, \r), '', $url); if (!headers_sent()) { if ($time) { echo $msg; } else { header(Location: $url); } exit; }}
/** * 页面跳转 * $url 跳转地址 * $time 一段时间后跳转 */ function app_redirect($url,$time=0,$msg='') { //多行URL地址支持 $url = str_replace(array("\n", "\r"), '', $url); if (!headers_sent()) { // redirect if(0===$time&&$msg=="") { if(substr($url,0,1)=="/") { if(defined("SITE_DOMAIN")) header("Location:".SITE_DOMAIN.$url); else header("Location:".$url); } else { header("Location:".$url); } }else { header("refresh:{$time};url={$url}"); //$time 后跳转 echo($msg); } exit(); }else { $str = ""; if($time!=0) $str .= $msg; exit($str); } }
本文共计145个文字,预计阅读时间需要1分钟。
PHP后端封装跳转功能,内容如下:
php/** * 页面跳转封装 * @param $url 跳转地址 * @param $time 一段时间后跳转 */function app_redirect($url, $time=0, $msg='') { // 多行URL地址支持 $url=str_replace(array(\n, \r), '', $url); if (!headers_sent()) { if ($time) { echo $msg; } else { header(Location: $url); } exit; }}
/** * 页面跳转 * $url 跳转地址 * $time 一段时间后跳转 */ function app_redirect($url,$time=0,$msg='') { //多行URL地址支持 $url = str_replace(array("\n", "\r"), '', $url); if (!headers_sent()) { // redirect if(0===$time&&$msg=="") { if(substr($url,0,1)=="/") { if(defined("SITE_DOMAIN")) header("Location:".SITE_DOMAIN.$url); else header("Location:".$url); } else { header("Location:".$url); } }else { header("refresh:{$time};url={$url}"); //$time 后跳转 echo($msg); } exit(); }else { $str = ""; if($time!=0) $str .= $msg; exit($str); } }

