为什么Cookie在CodeIgniter中不起作用? [英] Why doesn't cookie work in CodeIgniter?

查看:103
本文介绍了为什么Cookie在CodeIgniter中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数登录($ 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);

}

我无法从此函数中取回Cookie:

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

请帮助 - 如何从CodeIgniter获取Cookie?

解决方案

它的问题与CI内置函数写入cookie。现在我改变了我现在是我设置的cookie一切

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

函数并返回

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

这是工作很好!


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?

解决方案

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!

这篇关于为什么Cookie在CodeIgniter中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆