IE8上的SetCookies出错

时间:2015-11-06 15:41:25

标签: javascript php internet-explorer-8

当我使用Ajax在控制器中调用方法时,以下代码在IE8上不起作用。

alert(document.cookie)没有显示任何内容。

控制器:player.php

public function checkPassword()
    {
        $this->writeLog(date('Y-m-d H:i:s') . ' : Protected video', dirname(dirname(__FILE__)) . "/logs/debug_" . date("Y-m-j") . ".log");
        header('Access-Control-Allow-Origin: *');
        session_start();
        $password = (isset($_SESSION['password']) && !empty($_SESSION['password'])) ? $_SESSION['password'] : $this->getVodPwd($this->input->get('id'),$this->input->get('client'),$this->input->get('source'));
        $name = (isset($_SESSION['name']) && !empty($_SESSION['name'])) ? $_SESSION['name'] : $this->input->get('name');
        if ($name && $password && $this->input->get('pass') == $password) {
            $this->writeLog(date('Y-m-d H:i:s') . ' : Valid password for ' . $name, dirname(dirname(__FILE__)) . "/logs/debug_" . date("Y-m-j") . ".log");
            setcookie("unlocked" . $name, "true", time() + $this->config->item('allow_protected_video_access'), "/");
            session_destroy();
            echo "access allowed";
        } else {
            $this->writeLog(date('Y-m-d H:i:s') . ' : Wrong password for ' . $name, dirname(dirname(__FILE__)) . "/logs/debug_" . date("Y-m-j") . ".log");
            echo "access denied";
        }
    }

JavaScript的:

$(document).on('click','#submit-form-mail',function(){
        if ($('#input-video-password').val() !== ""){
            $.ajax({
                url: "<?php echo base_url(); ?>player/checkPassword",
                type: 'GET',
                data: {
                    id:'<?php echo $videoId; ?>',
                    source:'<?php echo $source; ?>'
                },
                dataType: "text",
                crossDomain: true,
                beforeSend: function (xhr) {
                xhr.setRequestHeader('Set-Cookie',  'PHPSESSID=<?php echo $unique; ?>');
                },
                success: function (data) {
                    if (data === "access denied") {
                        $('#input-video-password').css({borderColor: "red", borderWidth: "1px"}).val("").attr('placeholder', '<?php echo $translate['wrong-password'] ?>');
                    } else {
                        alert(document.cookie);
                    }
                }
            });
        }

0 个答案:

没有答案