Welcome Guest, Not a member yet? Register   Sign In
cookie will not set
#1

[eluser]Kyle Ellman[/eluser]
Hello, I'm trying to set a cookie to make sure a user has a username and password to access the admin portion of the site.

I'm using this code:
Code:
function login()
    {
        $data['error'] = '';
        
        if($_POST != NULL)
        {
            $loggedin = false;
            $query = $this->db->get_where('users', array('user' => $_POST['user']));
            if ($query->num_rows() > 0)
            {
                foreach ($query->result() as $row)
                {
                    if($row->password == $_POST['password'])
                        $loggedin = true;
                }
            }
            
            if($loggedin)
            {
                
                $host = $_SERVER['HTTP_HOST'];
                if(substr($host, 0, 4) == 'www.')
                    $host = substr($host, 4, strlen($host)-1);
                
                $cookie = array('name' => 'loggedin', 'value' => 'yipee!', 'expire' => '31556926', 'domain' => $host);
                set_cookie($cookie);
                //redirect('admin');
                if(get_cookie('loggedin'))
                    $data['error'] = 'cookie is set!';
                else
                    $data['error'] = 'cookie not set';
            }
            else
            {
                $data['error'] = '<h3 style="color:red">ERROR: Wrong username/password combination</h3>';
            }
        }
        
        $data['title'] = $this->info_model->get_info('title');
        $this->load->view('admin/login', $data);
    }

When I try login, I always get the "cookie not set" message, telling me that the password is correct, and $logged in is getting set to true, but the cookie is simply not setting.

Any help would be appreciated.

Thanks.


Messages In This Thread
cookie will not set - by El Forum - 07-04-2009, 12:54 PM
cookie will not set - by El Forum - 07-04-2009, 01:24 PM
cookie will not set - by El Forum - 07-04-2009, 01:28 PM
cookie will not set - by El Forum - 07-04-2009, 01:50 PM
cookie will not set - by El Forum - 07-07-2009, 04:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB