【问题标题】:Set-Cookie not working in IESet-Cookie 在 IE 中不起作用
【发布时间】:2012-11-09 03:31:55
【问题描述】:

我正在使用 Set-Cookie 功能..它在 chrome 和 firefox 中运行良好。

它设置了 cookie,我可以在 firebug 中看到它。

但由于某种原因,它没有在 I.E 中设置 cookie

谁能验证我的语法是否正确或我做错了什么?

    function generateSession($cookieName="wic_secure_sess", $idTag="", $numChars=32, $expireSeconds=0, $path=null, $domain=null, $secure=2) {
        if (!isset($_COOKIE[$cookieName])) {
            $sessId = $idTag;
            for ($i=0; $i<$numChars; $i++) {
                srand((double)microtime()*1000000);
                $randomType=rand(1, 3);
                srand((double)microtime()*1000000);
                switch ($randomType) {
                case 1:
                    $sessId.=chr(rand(65, 90));
                    break;
                case 2:
                    $sessId.=chr(rand(97, 122));
                    break;
                case 3:
                    $sessId.=rand(0, 9);
                    break;
                }
            }

        $expires = str_replace('+0000', 'GMT', gmdate('r', strtotime('+30 days')));
            if ($expireSeconds != 0) {
                $expireSeconds = time()+$expireSeconds;
            }

            if (livecheck() || stagecheck()) {
            header( "Set-Cookie:". $cookieName."=".$sessId."; expires=".$expires."; path=".$path.";HttpOnly;secure;");

            }
            else {



                     header( "Set-Cookie:". $cookieName."=".$sessId.";               expires=".$expires."; path=".$path.";HttpOnly");

            }   



        } else {
            $sessId = $_COOKIE[$cookieName];
        }
        return $sessId;
    }
?>
I dont want to use setcookie() because i am running php4 version since php4 does not support httponly in the setcookie() function

编辑:php setcookie() 函数在 IE 中运行良好。当我使用 header() 时,这会产生问题。

setcookie($cookieName, $sessId, $expireSeconds, $path, $domain, $secure);

这是对我的函数的调用:

generateSession( "my_sess", "", 20, 14400, "/");

【问题讨论】:

    标签: html cookies php4 setcookie


    【解决方案1】:

    您可能需要考虑使用P3P privacy policy。这种策略格式目前仅被 Internet Explorer 接受,但有助于克服浏览器隐私策略中的 cookie 阻止。 P3P 隐私策略有两个部分:策略文件和紧凑策略头。对于大多数应用程序而言,紧凑的策略标头通常就足够了,而且实现起来也最省力。为了简洁起见,P3P 的不同类别在标题中都有紧凑的代码,例如导航 => 资产净值。至少,我将从紧凑策略的交互式 (INT)、导航 (NAV) 和唯一 ID (UNI) 代码开始。

    在 Grails/Java 中,这是一个如何传回标头的示例:

    response.setHeader("P3P", "CP='INT NAV UNI'");
    

    【讨论】:

      猜你喜欢
      • 2018-11-03
      • 2012-03-09
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 2017-07-19
      • 1970-01-01
      相关资源
      最近更新 更多