php session_id更改标头重定向

时间:2014-01-11 10:15:25

标签: javascript php cookies session-cookies

我想要做的是在每次重定向中增加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> 

1 个答案:

答案 0 :(得分:0)

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

PHP:session_start()