http-equiv实现跳转与header跳转有啥区别?还是这两个就没有任何区别

WBOY
Release: 2016-06-06 20:42:41
Original
935 people have browsed it

<code><br>session_start();
if(isset($_SESSION['userId'],$_SESSION['name'],$_SESSION['rights'])){



    echo "<meta http-equiv='\"refresh\"' content='\"0;url=mannager.php\"'>";

}


else{

    echo "<meta http-equiv='\"refresh\"' content='\"0;url=login.php\"'>";
}
</code>
Copy after login
Copy after login

如上代码,这个与header实现跳转有什么不一样呢?

回复内容:

<code><br>session_start();
if(isset($_SESSION['userId'],$_SESSION['name'],$_SESSION['rights'])){



    echo "<meta http-equiv='\"refresh\"' content='\"0;url=mannager.php\"'>";

}


else{

    echo "<meta http-equiv='\"refresh\"' content='\"0;url=login.php\"'>";
}
</code>
Copy after login
Copy after login

如上代码,这个与header实现跳转有什么不一样呢?

区别就是:

meta redirect可以应用于, http headers已经发送出去的情况. 比如网页已经渲染了一半,却要做跳转. 还有个好处就是可以延时跳转.

header redirect就是, http headers还没发送时做跳转, 比如,网页一打开, 还没渲染, 就跳转. 这个时候用header("Location: url", $status_code). 还可以加status code而前者就不行了.

我更倾向于header, 用meta redirect, 偶尔遇到过跳转没成功, 变空白. header redirect可以加status_code, 对于seo还是比较好的.

像你这个代码, 用header吧. session_start(); 只有在http headers还没发送时,才能调用成功.

如果一定要用meta redirect, 建议后面加个 exit;


仔细想想,一个在服务端,一个在浏览器,没啥好比较的..... :[

Related labels:
php
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