This article mainly introduces three methods of using cookies in CodeIgniter, which are simple and practical. if you need them, refer to the CI framework.
Cookie is widely used in php programming. the following three methods are used in CodeIgniter, which can be used by readers according to their project requirements.
Method 1: use the original php method to set the cookie value
setcookie("user_id",$user_info['user_id'],86500);setcookie("username",$user_info['username'],86500);setcookie("password",$user_info['password'],86500);//echo$_COOKIE['username'];
Method 2: Set the cookie value through the input class library of the CI framework
$ This-> input-> set_cookie ("username", $ user_info ['username'], 60); $ this-> input-> set_cookie ("password ", $ user_info ['password'], 60); $ this-> input-> set_cookie ("user_id", $ user_info ['User _ id'], 60 ); // echo $ this-> input-> cookie ("password"); // applicable to controller // echo $ this-> input-> cookie ("username "); // applicable to controller // echo $ _ COOKIE ['username']; // you can obtain the cookie value in the model class in this way // echo $ _ COOKIE ['password']; // you can obtain the cookie value in the model class in this way.
Method 3: Use the cookie_helper.php helper function library in the CI framework to set the cookie value.
set_cookie("username",$user_info['username'],60);set_cookie("password",$user_info['password'],60);set_cookie("user_id",$user_info['user_id'],60);//echoget_cookie("username");