Please help me with Cookie

Hi all. I want my website to show the colorbox on the first visit. After searching the sollution for a while, i decided to use the cookie to check whether it is the first visit or not. This is my code :





    $cookie = (isset(Yii::app()->request->cookies['web_visited'])) ? Yii::app()->request->cookies['web_visited']->value : '';

    

    if($cookie == '')

    {

        Yii::app()->clientScript->registerScript('',

        "$('document').ready(

        function()

        {

                $.fn.colorbox({href:'index.php?r=site/login&s=1', open:true});

        }

        )");


        $colorbox = $this->widget('application.extensions.colorpowered.ColorBox');

        $colorbox

            ->addInstance('.colorbox', array('maxHeight'=>'80%', 'maxWidth'=>'80%'));


        Yii::app()->request->cookies['web_visited'] = new CHttpCookie('web_visited', 'yes');

    }




But every time i reload the page the colorbox keeps on showing, meaning that I fail to set the cookie.

And if i set the cookie before calling the colorbox, the colorbox doesnt show.





    $cookie = (isset(Yii::app()->request->cookies['web_visited'])) ? Yii::app()->request->cookies['web_visited']->value : '';

    

    if($cookie == '')

    {

        Yii::app()->request->cookies['web_visited'] = new CHttpCookie('web_visited', 'yes');


        Yii::app()->clientScript->registerScript('',

        "$('document').ready(

        function()

        {

                $.fn.colorbox({href:'index.php?r=site/login&s=1', open:true});

        }

        )");


        $colorbox = $this->widget('application.extensions.colorpowered.ColorBox');

        $colorbox

            ->addInstance('.colorbox', array('maxHeight'=>'80%', 'maxWidth'=>'80%'));


        

    }




Does anyone know how to fix this? Please advice =) thanks

Oops, im sorry, my fault. I forgot to add the ->value when checking the cookie.

isset(Yii::app()->request->cookies[‘web_visited’]->value)

Now it works well. Thanks =)