标头与内容重定向 [英] header vs content redirect

查看:72
本文介绍了标头与内容重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,除非在HTML内容之前发送,否则PHP中的header()函数会导致错误输出,因此,我正在考虑使用HTML内容重定向作为替代.例如:

As we know it, the header() function in PHP causes error ouputs unless sent before an HTML content, so instead of using output buffering or worse yet, suppressing the famous "headers already sent " error, I was thinking of using the HTML content redirect as an alternative. ex:

if($userRegister){ ?>
   <meta http-equiv="refresh" content="0; URL=success.php" /> 
<?php }

由于我还没有看到这种方法,所以我想知道我缺少一些东西.因为这似乎是一种很好的页面重定向方法

As I have not seen this approach, I would like to know there is something I am missing. Because it seems quite a good approach for page redirection

推荐答案

请参阅:

see: Is it good practise to use meta refresh tags for redirects instead of header() function in php?

两种方法都有其起伏.

最好使用header(),因为它将向客户端发送较小的有效负载,并且不会因浏览器加载另一个页面的DOM而引起副作用.

in my opinion it is better to use header() as it sends a smaller payload to the client and it won't cause side effects from the browser loading the DOM of another page.

这篇关于标头与内容重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆