Welcome Guest, Not a member yet? Register   Sign In
cookie won't set
#1

[eluser]SomeFunkyDude[/eluser]
I tried making a controller called "cookie" that sets a cookie in the constructor, then making a simple page2() segment that displays whether the cookie was set or not, but the cookie state keeps returning FALSE

Code:
<?php

class Cookie extends Controller {
    
    function Cookie()
    {
        parent::Controller();
        $this->load->helper('cookie');
        $cookie = array(
                   'name'   => 'cookie_name',
                   'value'  => 'w00t!',
                   'expire' => '1000000',
                   'domain' => '.localhost',
                   'path'   => '/',
                   'prefix' => 'myprefix_',
               );
        set_cookie($cookie);
    }
    
    function page1()
    {
        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_name') === TRUE)
        {
            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



Theme © iAndrew 2016 - Forum software by © MyBB