在PHP中使用元刷新标记进行重定向而不是使用header()函数是不错的做法吗? [英] Is it good practise to use meta refresh tags for redirects instead of header() function in php?

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

问题描述

我必须在我的脚本中使用很多重定向,例如在用户登录后我需要将它们重定向到管理区域等等。但是我觉得不方便总是必须将标题功能放在顶部。因此,如果我使用元刷新标记作为我的重定向,那么根据最佳做法会让这些标记皱起眉头,还是可以接受?

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


解决方案

/ strong> 维基百科明确指出:

< blockquote>

Meta刷新是一种劝阻网页浏览器在给定时间间隔后自动刷新当前网页或框架的劝阻方法.....




元刷新标记有一些缺点


  1. 页面重定向过快(少于2-3秒),使用下一页上的返回按钮可能会导致一些浏览器移回重定向页面,重定向将再次发生。这对可用性不利,因为这可能会导致读者在最后一个网站上卡住。

  2. 读者可能希望或不希望被重定向到不同的页面,这可能会导致用户不满意或引发安全问题。

  3. 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. The Wikipedia clearly states:

    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.....

    Meta refresh tags have some drawbacks:

    1. If a page redirects too quickly (less than 2-3 seconds), using the "Back" button on the next page may cause some browsers to move back to the redirecting page, whereon the redirect will occur again. This is bad for usability, as this may cause a reader to be "stuck" on the last website.
    2. A reader may or may not want to be redirected to a different page, which can lead to user dissatisfaction or raise concerns about security.

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

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