获取cookie值的未定义索引

时间:2017-08-15 14:17:59

标签: php cookies undefined

我正在尝试此代码:

<?php
    $cookie_name = "idmarket";
    $coolie_value = "1";

    if (!isset($_COOKIE[$cookie_name])){
        echo "Cookie wasn't set";
        setcookie($cookie_name,$coolie_value,time() + 86400);
        echo "Now cookie set : " . $_COOKIE[$cookie_name];
    } else {
        echo "Cookie have been set : ".$_COOKIE[$cookie_name];
    }
?>

如果没有设置cookie,我想做点什么,如果没有设置就什么都不做。但是当我尝试测试现在是否设置了cookie并且回显$ _COOKIE [$ cookie_name]时,我得到了Notice: Undefined index: idmarket

0 个答案:

没有答案