PHP检查cookie是否存在,等于NULL,或存在[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我有一个登录表单和PHP处理器。当我得到所有代码都正确时,即使cookie存在,我的PHP仍会重定向回登录表单...

    <script >

  function redir2()


// Original JavaScript code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header. 
{
    function getCookie(user) {
        var re = new RegExp(name + "=([^;]+)");
        var value = re.exec(document.cookie);
        return (value != null) ? decodeURI(value[1]) : null;
    }
    // End of code by Chirp Internet, rest of code done by Joey's Place 
Productions, Ltd.
    document.write(getCookie("user")); // <--- For debugging so i can see if 
cookie('user') == Null || Value
    var cookie = getCookie("user");
    if (cookie == "" || "null") {
        window.location.href = "/a.html";
    } else {}
} 
   </script>

<?php
 if(isset($_cookie['user'])) {
if($_COOKIE['user'] == '8877321829'){

    echo 'debug1' ; 
}
else{

  echo "<script> redir2(); </script>";
}
} else {

    echo "<script> redir2() </script>";
}

有人能告诉我我做错了什么,需要修理什么......对我奇怪的缩进和代码感到抱歉。我是初学者,因为这只是我的第二篇文章。如果您需要更多信息,我也可以为您提供登录网站的代码

javascript php html cookies login
1个回答
0
投票

$_cookie应该是帽子。将其更改为$_COOKIE,它应该工作。

© www.soinside.com 2019 - 2024. All rights reserved.