【问题标题】:php session_id change on header redirect标头重定向上的php session_id更改
【发布时间】:2014-01-30 09:55:53
【问题描述】:

我想要做的是在每次重定向中增加 COOKIE 中的值...但每次我检查 cookie 是否存在时它都不存在。

我也尝试使用 SESSION 来做,但是每次重定向中的 session_id 都会发生变化(我猜测重定向会出于某种原因创建一个新会话)

这是我的代码

<script language="javascript">
    var popexurl = "<?php echo $PopExitUrl ?>";
    if(popexurl != ""){
    (function() {
        setTimeout(function() {

            <?php 

                if (isset($_COOKIE["count"]))
                {
                    //cheak user refreshes

                             $cookie = (int)++$_COOKIE['count'];
                             setcookie("count", $cookie, time()+3600);

                }
                else 
                {
                       setcookie("count", 1, time()+3600);
                       $cookie=0;

                }

            ?>

        var __redirect_to = '<?php echo $PopExitUrl; ?>';//

        var _tags = ['button', 'input', 'a'], _els, _i, _i2;
        for(_i in _tags) {
            _els = document.getElementsByTagName(_tags[_i]);
            for(_i2 in _els) {
                if((_tags[_i] == 'input' && _els[_i2].type != 'button' && _els[_i2].type != 'submit' && _els[_i2].type != 'image') || _els[_i2].target == '_blank') continue;
                _els[_i2].onclick = function() {window.onbeforeunload = function(){};}
            }
       }

        window.onbeforeunload = function() {
          window.scrollTo(0,0); 
          document.getElementById('ExitBackDiv').style.display = 'block';       
             document.getElementById('ExitDiv').style.display = 'block';
            setTimeout(function() {
                window.onbeforeunload = function() {};
                setTimeout(function() 
                {
                   window.location = __redirect_to;
                }, 500);
           },5);
            <?php
            if ($PopupMessage == ""){
            $PopupMessage= "\\n**********************\\nWAIT! WAIT! WAIT! WAIT!\\n\\n**********************\\n\\nDont Miss This LAST CHANCE to become Financially Secure and CHANGE YOUR Lifestyle!!!\\n\\n...Click STAY ON THIS PAGE to activate your LIMITED time offer!";}

                    ?>

      var popmsg = "<?php echo $PopupMessage ?>";  


    if (navigator.userAgent.indexOf("Firefox")!=-1)
    {
    //setTimeout('window.location="'+__redirect_to+'"', 10);
     window.alert(popmsg); 
     return popmsg;


      }
    else
     {
            return popmsg;

            }

        }            
        }, 500);

    })();
    }
    </script> 

【问题讨论】:

    标签: javascript php cookies session-cookies


    【解决方案1】:

    session_start(); 基于通过GETPOST 请求或通过cookie 传递的会话标识符创建会话或恢复当前会话。

    PHP:session_start()

    【讨论】:

    • 那又怎样?,我知道 session_start() 做了什么
    • 那么,你知道你在setcookie()之前发送了标题html吗?
    猜你喜欢
    • 1970-01-01
    • 2021-07-07
    • 2011-09-22
    • 1970-01-01
    • 2013-08-22
    • 2012-12-16
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多