在 php 中使用元刷新标签而不是 header() 函数进行重定向是一种好习惯吗? [英] Is it good practise to use meta refresh tags for redirects instead of header() function in php?

查看:20
本文介绍了在 php 中使用元刷新标签而不是 header() 函数进行重定向是一种好习惯吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的脚本中使用很多重定向,例如,在用户登录后,我需要将它们重定向到管理区域等.但我发现总是必须在最顶部使用标题功能很不方便.因此,如果我使用元刷新标签进行重定向,根据最佳实践,这是否会令人不悦,还是可以接受?

I have to use redirects a lot in my scripts, for example after a user logs in I need to redirect them to the admin area, etc. But I find it inconvenient to always have to have the header function at the very top. So if I use the meta refresh tags for my redirects, is that something that would be frowned upon according to best practices or is it acceptable?

function redirect($location) {
    echo "<meta http-equiv='refresh' content='0; url=$location' />";
}

推荐答案

No. 维基百科明确指出:

元刷新是一种不鼓励使用的方法,它指示网络浏览器在给定时间间隔后自动刷新当前网页或框架.....

Meta refresh is a discouraged method of instructing a web browser to automatically refresh the current web page or frame after a given time interval.....

元刷新标签有一些缺点:

  1. 如果页面重定向过快(少于 2-3 秒),使用下一页上的返回"按钮可能会导致某些浏览器返回到重定向页面,此时会再次发生重定向.这不利于可用性,因为这可能会导致读者卡"在最后一个网站上.
  2. 读者可能希望也可能不希望被重定向到不同的页面,这可能会导致用户不满或引发对安全性的担忧.

这篇关于在 php 中使用元刷新标签而不是 header() 函数进行重定向是一种好习惯吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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