简体   繁体   English

<meta http-equiv="refresh" content="0; url=http://www.xxxxxxl.com/index.php" />不清爽

[英]<meta http-equiv="refresh" content="0; url=http://www.xxxxxxl.com/index.php" /> is not refreshing

I had a (very) simple login script which was working beautifully, and somehow, without much, if any, changes on the script page I have the following error:我有一个(非常)简单的登录脚本,它运行良好,不知何故,脚本页面上没有太多更改,如果有的话,我有以下错误:

The Problem问题

<meta http-equiv="refresh" content="0; url=http://www.xxxxxx.com/index.php" />

The above code is not refreshing, which means the user is not getting redirected after login.上面的代码没有刷新,这意味着用户在登录后没有被重定向。 He/she has to manually refresh the page to start his/her session:他/她必须手动刷新页面才能开始他/她的会话:

在此处输入图片说明

As you can see from above image, the login was successful, but the page isn't refreshing.从上图可以看出,登录成功,但页面没有刷新。

Please note using header("location:") is not an option here:请注意使用header("location:")不是这里的选项:

Also note I'm using Ajax with the form submission for what that is worth...另请注意,我将 Ajax 与表单提交一起使用,以获取价值...

Part of the login script:登录脚本的一部分:

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // Do stuff
    if(mysqli_num_rows($result) = 1) {
        while
        {
            // GET session variables
        }//while
        echo 'Success! Logging In....';
        echo '<meta http-equiv="refresh" content="0; url=http://www.xxxxx.com/index.php" />'//now refresh page
    } //if
} //if

Strangely, this was working for me above, but it has since yesterday stopped working.奇怪的是,这在上面对我有用,但从昨天起它就停止工作了。

Solution解决方案

Is there a reason why this is not working?这有什么原因不起作用吗?

Is there anything I can do to fix this?我能做些什么来解决这个问题吗?

Is there any alternative approach?有什么替代方法吗?

The way you are trying to do it will not work, because the <meta> tag is supposed to come in the <head> section of your page, not in the body.您尝试这样做的方式是行不通的,因为<meta>标签应该出现在页面的<head>部分,而不是正文中。 Plus, you can't use <meta http-equiv="refresh"> or any other header directives once output is sent.另外,一旦发送输出,您就不能使用<meta http-equiv="refresh">或任何其他标头指令。

Try replacing this part:尝试更换这部分:

echo '<meta http-equiv="refresh" content="0; url=http://www.xxxxx.com/index.php" />'

with this:有了这个:

echo '<script>location.href="http://www.xxxxx.com/index.php"</script>';

A better way to do this would be to use PHP to change the headers:更好的方法是使用 PHP 更改标题:

header( "refresh:0;url=index.php" ); instead of your echo for the meta tag而不是您对元标记的echo

You seem to be confusing all the technologies you are using to build your site.您似乎混淆了用于构建站点的所有技术。 In the end you have nothing but plain HTML and it should look like this:最后你只有纯 HTML,它应该是这样的:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="refresh" content="5; url=http://www.google.com/">
    </head>

    <body>
        <p>Redirecting in 5 seconds...</p>
    </body>
</html>

How you generate this code is irrelevant from the browser point of view.从浏览器的角度来看,如何生成此代码无关紧要。

Browsers are designed to be very permissive about invalid HTML and you've pushed it to the limit.浏览器被设计为对无效 HTML 非常宽容,而您已经将其推到了极限。 Yet both Firefox and Chrome see to handle even this just fine:然而,Firefox 和 Chrome 都能很好地处理这种情况:

Not redirecting
<meta http-equiv="refresh" content="5; url=http://www.google.com/"></head>

So there must be something else you haven't shared.所以一定还有一些你没有分享的东西。

Having said that, this is the weirdest way to redirect.话虽如此,这是重定向的最奇怪的方式。 I didn't even know people were still using it in 2015. Since you have PHP, leverage it:我什至不知道人们在 2015 年还在使用它。既然你有 PHP,就利用它:

header('Location: http://www.xxxxxx.com/index.php');
exit;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用变量值<meta http-equiv="refresh" content=" url="/> ? - Using a variable value in <meta http-equiv="refresh" content=" url="/>? PHP:打印&#39; - PHP: print '<meta http-equiv=“refresh” content="0;url=' with URL parameters 目的 <meta http-equiv=“refresh”> 在单独的文件中使用递归URL - Purpose of <meta http-equiv=“refresh”> with recursive URL in a separate file 在IE11中不起作用-meta http-equiv =“ refresh” content =“ 0; url = - Not working in IE11 - meta http-equiv=“refresh” content="0;url= 如何在没有meta http-equiv = REFRESH CONTENT = time的几秒钟内在PHP中重定向页面 - How to Redirect Page in PHP after a few seconds without meta http-equiv=REFRESH CONTENT=time 用php提取http-equiv内容 - Extract http-equiv content with php 在正文中使用meta http-equiv = refresh而不是head标签作为php redirect的替代方法是否安全? - is it safe to use meta http-equiv=refresh in the body rather than the head tag as an alternative to php redirect? 通过PHP标头或HTML元http-equiv发送文档信息? - Sending document information by PHP header OR HTML meta http-equiv? codeigniter网址http://www.website.com/index.php/index.php/page - codeigniter url http://www.website.com/index.php/index.php/page (localhost)meta http-equiv在Android浏览器上不起作用 - (localhost) meta http-equiv don't work on android browsers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM