Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

php - Why doesn't cookie work in CodeIgniter?

I use this function to add cookie and it adds perfectly as I can see in browser options.

function login($username,$password){

    $cookieUsername = array(
        'name'   => 'user',
        'value'  => md5($username),
        'expire' => time()+1000,
        'path'   => '/',
        'secure' => TRUE
    );

    $cookiePassword = array(
        'name'   => 'pass',
        'value'  => $password,
        'expire' => time()+1000,
        'path'   => '/',
        'secure' => TRUE
    );

    $this->input->set_cookie($cookieUsername);
    $this->input->set_cookie($cookiePassword);

}

I am unable to get back the cookie from this function:

 echo $this->input->cookie('user');

Please help - how can I get cookie back from CodeIgniter?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Its problem with CI built in function which writes the cookie. What i changed is now i am setting cookie whith

setcookie($name,$value,$expire,$path); 

function and getting it back through

$this->input->cookie('user',TRUE); 

this is work damn fine!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...