• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cookie won't set

#3
[eluser]SomeFunkyDude[/eluser]
okay, i revised the cookie to be set only if get_cookie('myprefix_cookie_name') returns false. Apparently
Code:
if (get_cookie('myprefix_cookie_name') === TRUE)
or
Code:
if (get_cookie('myprefix_cookie_name') === FALSE)
wasn't analyzing the Boolean state for some reason.

I tried
Code:
if (get_cookie('myprefix_cookie_name') { execute code }
and it seemed to work.

Code:
<?php

class Cookie extends Controller {
    
    function Cookie()
    {
        parent::Controller();
        $this->load->helper('cookie');
    }
    
    function page1()
    {
        if (!get_cookie('myprefix_cookie_name2'))
        {
            $cookie = array(
                       'name'   => 'cookie_name2',
                       'value'  => 'w00t!2',
                       'expire' => '1000000',
                       'path'   => '/',
                       'prefix' => 'myprefix_',
                   );
            set_cookie($cookie);
        }
        echo get_cookie('myprefix_cookie_name2');
        echo "<p>This is page 1!</p>";
        echo '<a href="page2">Page 2</a>';
    }
    
    function page2()
    {
        echo "<p>This is page 2!</p>";
        if (get_cookie('myprefix_cookie_name2'))
        {
            echo "<p>Cookie is set</p>";
        } else {
            echo "<p>Cookie not set</p>";
        }
        echo '<a href="page1">Page 1</a>';
    }
}

?&gt;


Messages In This Thread
cookie won't set - by El Forum - 04-11-2009, 01:58 PM
cookie won't set - by El Forum - 04-11-2009, 02:05 PM
cookie won't set - by El Forum - 04-11-2009, 02:26 PM
cookie won't set - by El Forum - 04-11-2009, 08:49 PM
cookie won't set - by El Forum - 09-05-2012, 11:22 AM
cookie won't set - by El Forum - 09-05-2012, 04:54 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.