Welcome Guest, Not a member yet? Register   Sign In
Cookie/Session value gets destroyed after redirect. Help please :(
#1

[eluser]debasishdebs[/eluser]
Code:
if ($checkgroupid == "1")
{
$data = array(
'username' => $this->input->post('username'),
'group' => $checkgroupid
);
$this->session->set_userdata($data);
echo $this->input->post('username');
echo $this->session->userdata('username');
setcookie("logged_user", $this->input->post('username'), time()+3600);
if(isset($_COOKIE["logged_user"]))
{
  redirect('admin/dashboard');
}
else
{
  echo "blabla";
}
After this it redirects to admin/dashboard controller meaning that cookie was set successfully.

Code:
$data1 = array(
  'username' => $this->session->userdata('username'),
  'group' => $this->session->userdata('group')
  );
  echo $this->session->userdata('username');
  echo "ddd";
  $this->session->set_userdata($data1);
  echo $this->session->userdata('username');
  echo $this->input->cookie('user1');  
  echo "111";

But after this, username is not echoed.
i.e.
Code:
echo $this->session->userdata('username');
echo $this->input->cookie('user1');
None of it works. Help me please.. What am I doing wrong?

Even i have loaded 'cookie' & 'session' libraries.
#2

[eluser]WanWizard[/eluser]
Which browser is used? Does it happen in all browsers? What is the hostname used? Is the cookie configuration ok, both in PHP (for the setcookie() function) and in CI (for the input->cookie method). And are the two in sync?
#3

[eluser]debasishdebs[/eluser]
Checked on firefox & chrome even after restarting browsers.
Host : localhost
What u said about cookie config? Didn't get you. Can you explain better?
#4

[eluser]InsiteFX[/eluser]
The browsers do not update a cookie until the next page refresh!

Set a cookie in your controller then try to read it after setting it!

It willl not work until you refresh the browser web page!
#5

[eluser]debasishdebs[/eluser]
Untill next page refresh? Means? I login, then on next page i keep on refreshing but nothing happens.

I have got $this->session->set_userdata(0 working on my anothe CI app, but dont know whats wrong here..
#6

[eluser]debasishdebs[/eluser]
Please some1 reply.. Its urgent Sad
#7

[eluser]vtx220[/eluser]
I'm sure if it's "urgent" you'd be willing to post this in the job section Tongue But anyways, it's been a while since I've used codeigniter's session class but shouldn't:

Code:
if(isset($_COOKIE["logged_user"]))

be...

Code:
if(isset($_SESSION["logged_user"]))

I say this because if I remember correctly (which I probably don't), the session class verifies the cookie for you, so you don't have to touch that part, only fetch data with session. I've only used this class once before, the rest was just phpbb managed so that could be wrong Tongue
#8

[eluser]InsiteFX[/eluser]
I told you before that you cannot check a cookie before a page refresh
but yet you are doing this!
Code:
setcookie("logged_user", $this->input->post('username'), time()+3600);

// this will not work because the cookie has not been written yet!
print_r($_COOKIE);

if(isset($_COOKIE["logged_user"]))
{
  redirect('admin/dashboard');
}
else
{
  echo "blabla";
}
#9

[eluser]debasishdebs[/eluser]
@vtx220 : I ll check with session and reply bak Smile
@InsiteFX : So cookie wont work till i redirect right? so isset($_COOKIE) should return false? But my controller redirects to 'admin/dashboard' . How?
#10

[eluser]CroNiX[/eluser]
Try:
Code:
if ($this->input->cookie('logged_user') === FALSE)




Theme © iAndrew 2016 - Forum software by © MyBB