Press "Enter" to skip to content

How to create Remember me function in PHP with CodeIgniter?

0

Hi Guys, In this tutorial I am going to create Remember me function in PHP with Cookie, Remember me function is used to save user password and username when user click on checkbox Remember me.

Before starting use CI Cookie Helper in your project.

$this->load->helper('cookie');

Now use set_cookie method to set the value in Cookie.

set_cookie("username", $user['email'], time() + (10 * 365 * 24 * 60 * 60));
set_cookie("userpassword", $input['password'], time() + (10 * 365 * 24 * 60 * 60));

Above code will store the cookie value and for making cookie value used below code. Please use this code when you are authenticating user credential. so credential stored in cookie is verified & correct.

set_cookie("username", "");
set_cookie("userpassword", "");

Now you can use below code to print the value of cookie, get_cookie

<input type="text" name="email" value="<?php echo get_cookie("username"); ?>"/>
<input type="password" name="password" value="<?php echo get_cookie("userpassword") ?>"/>

Happy Coding!

How to Install Let’s encrypt free SSL on Ubuntu step-by-step process?
How to connect MongoDB with PHP CodeIgniter.