Search code examples
codeignitercookiesbrowserinspect-element

Unable to view cookie in the browser (codeigniter)


I'm attempting to check out the contents of a cookie I'm setting using CodeIgniter. I am able to dump the contents of the cookie array correctly server-side, but unable to view them in the inspector in my browser (so client-side).

I am using CodeIgniter version 3, if that helps. This is the code where I set the cookie:

 if ($email === $admin_email && $password = $password) {

            echo 'credential match';

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

            if ($remember_me == '1') {                            

                $email    = $this->input->post('email');
                $password    = $this->input->post('password');
                $remember = $this->input->post('remember_me');

                $cookie1 = array(
                    'name' => 'email',
                    'value' => $email,
                    'expire' => '86400',
                    'domain' => base_url(),
                    'path' => '/admin/',
                    'prefix' => 'myprefix_',
                    'secure' => TRUE
                );

                $this->input->set_cookie($cookie1);
                echo "<pre>";


                var_dump($cookie1);
                echo"</pre>";
                echo 'Checked';
            }

        }
    return TRUE; // if credential matches
    } else {
        return False;
    }

Here's an image to clarify what I mean: cookie


Solution

  • Solved ,marked 'secure' => FALSE

                    // set cookie 
                      $cookie = array(
                        'name' => 'email',
                        'value' => $email,
                        'expire' => '86500',
                        'domain' => '.xyzsoftsolutions.com',
                        'path' => '/admin',
                        'prefix' => 'admin_',
                        'secure' => FALSE
                    );
    
                    $this->input->set_cookie($cookie);