Welcome Guest, Not a member yet? Register   Sign In
Facing problem with set_cookie
#1

[eluser]Hiraman Patil[/eluser]
Hello all

I am new with code igniter + PostgreSQL

please help on following code.
I am trying to set cookie here.
but not success yet.

This is my code
if($this->input->post('rememberme') == 'yes')
{
$this->load->helper('cookie');
$cookie = array('login_email' => $this->input->post('email'),
'login_password' => $this->input->post('password'));
set_cookie($cookie);
}

please give suggestion on this
and also how can I access the cookie variable in controller.

thanks
#2

[eluser]Craig A Rodway[/eluser]
The cookie is not being set because you are not using the correct syntax. Please check the Cookie Helper documentation and adjust your code.

Hint: You will need to call set_cookie() twice if you want to set two cookies.

I'd also like to point out that storing a user's password in a cookie is insecure and considered bad practice.
#3

[eluser]flaky[/eluser]
you don't have to use set_cookie
use the codeigniter session which by default saves the information in the cookie
Code:
$this->load->library('session');

$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => '[email protected]',
                   'logged_in' => TRUE
               );

$this->session->set_userdata($newdata);
#4

[eluser]paulon[/eluser]
[quote author="flaky" date="1261684028"]you don't have to use set_cookie
use the codeigniter session which by default saves the information in the cookie
Code:
$this->load->library('session');

$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => '[email protected]',
                   'logged_in' => TRUE
               );

$this->session->set_userdata($newdata);
[/quote]

what if i dont want to use $this->session->set_userdata($newdata);
because i dont want to save the information in the cookie.
i want to avoid some user who login then close the browser then reopen the site the same session will load, is their other alternative?
#5

[eluser]flaky[/eluser]
then use
Code:
$_SESSION['some_var'] = 'some value';
#6

[eluser]flaky[/eluser]
check this solution, it's what you are looking for
http://ellislab.com/forums/viewthread/70036/
#7

[eluser]Hiraman Patil[/eluser]
thanks for all your help.
#8

[eluser]Hiraman Patil[/eluser]
Hi flaky

Suppose I am using your solution.
then
If I logged out from site then how can I fetch data from session ?
I want to store data in cookie to show automaticcally on login page when user logged out.
#9

[eluser]flaky[/eluser]
if you are using CI session then, the moment the user clicks logout you could save that in the session
example
Code:
public function logout(){
    //destroy the session
    $this->session->destroy();
    // Something like: Monday 8th of August 2005 03:12:46 PM
    $this->session->set_userdata('last_logout_date', date('l jS \of F Y h:i:s A'));
}

.
.
.

public function login(){
    $this->load->view('user_login', array('last_logout_date' => $this->session->userdata('last_logout_date')));
}

and when the user wants to login you just read the session




Theme © iAndrew 2016 - Forum software by © MyBB