开发者

Cookies replacement question

My question is the following: I have a pair of buttons in my site, and once I click one of the buttons, it's going to set a cookie using setcookie();. Now that a cookie is set, the user decides to click the other button, which sets a new cookie BUT it has the same cookie name as the cookie the user set earlier - Now it has a different value though.

Will the second clicked button change the value of the first set cookie? This is all I need to know.

Thanks.

if (!isset($_COOKIE['imgit_style']))
{
    if (isset($_POST['green']))
    {
        setcookie('imgit_style', 'green', time()+31556952);
    }
    else if (isset($_POST['blue']))
    {
        setcookie('imgit_st开发者_高级运维yle', 'blue', time()+31556952);
    }
}
else if (isset($_COOKIE['imgit_style']))
{   
    echo $_COOKIE['imgit_style'];
    if (isset($_POST['green']))
    {
        setcookie('imgit_style', 'green', time()+31556952);
        $style = '';
    }
    else if (isset($_POST['blue']))
    {
        setcookie('imgit_style', 'blue', time()+31556952);
        $style = '_' . $_COOKIE['imgit_style'];
    }
}

This is my code, and the last else if statement is not changing my cookie value to "blue", it stays green.


Yes .. it will replace cookie's old value with new one ..


Yes.

Setting an existing cookie will overwrite it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜