Remember the functionality in codeigniter


I have implemented remember me functionality as this question

How to create "remember me checkbox" using Codeigniter session library?

first answer. I created a cookie with a random number code as value and it stored in db(user table). On login, db code checks with cookie value.It works fine on my localhost server. But in live server which has a subdomain url has problem.Also I tested it with another server with ip address as url. There also it is not working. In both cases cookie created but cant read the cookie. Please help me.

cookie set by

$auto_login_hash_code = uniqid();
$domain = $_SERVER['SERVER_NAME'];
$cookie = array(
            'name' => 'rememberMe',
            'value' => $auto_login_hash_code,
            'expire' => 31536000,
            'domain' => $domain,
            'path' => '/'

and reading cookie by

    if (get_cookie('rememberMe')) {
$hashcode = $this->CI->input->cookie('rememberMe');
$this->CI->load->model('loginmodel', '', true);
$username = $this->CI->loginmodel->get_username_by_hashcode($hashcode);//in this function setting session variables

Thanks in advance iijb

you are getting library for that on github. search remember me on github, load it and just follow below steps. Verify cookie if token is present in database go to home page

            $cookie_user = $this->rememberme->verifyCookie();
            if ($cookie_user)

            // If checkbox is checked it return true either false
            $checked = (isset($_POST['Checkbox1']))?true:false;  

            if($checked== true)

                    //$this->rememberme->setCookie('set cookie here');

dont set anything