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

[eluser]debasishdebs[/eluser]
Code:
echo "2222";
   $user = $this->input->post('username');
   echo $user;
   if($this->access->login($this->input->post('username'),$this->input->post('password')))
   {
   //Check which group user belongs to, and if it is an Administrator login
   //Redirect to Admin dashboard otherwise it's a regular menu and redirect to referrer or member page.
   $checkgroupid= $this->session->userdata('group_id');
   echo $checkgroupid;     //It doesnt return anything i.e. blank
   if ($checkgroupid == "1") {    //SO file never enters here
    $data = array(
    'username' => $this->input->post('username'),
    'group' => $checkgroupid,
    'is_logged_in' => true
   );
   $this->session->set_userdata($data);
   setcookie("logged_user", $this->input->post('username'), time()+3600);

    redirect('dashboard');
    echo "blabla";

   }
   $uri = $this->session->flashdata('referrer') ? $this->session->flashdata('referrer') : 'member';
   redirect($uri);
   }
   else {
    echo "jsjsjs";
   }
  }
Mo modified controller :
It gives following output. I sesiourly think there is problem with cookies. Because here also cookie wont work Sad

If its not working can anyone suggest me a forum? I m doing it for a forum in CI. It can be anything but I can integrate its login system with my existing authentication. (Custom made auth). Vanilla doesn't worm for me also Sad
#12

[eluser]vbsaltydog[/eluser]
Your code is heavily flawed. You are trying to get the group id out of the session but you didn't put it in the session. You are trying to echo data after a redirect. Here is breakdown of the cookie setting process:

Browser sends HTTP request -> Server prints the cookie info in the HTTP response header -> browser receives the cookie info -> browser sets the cookie file.

Since the browser received the cookie in the server response header, it used it to set the cookie file but the cookie is not available to the server until the NEXT http server request.
#13

[eluser]debasishdebs[/eluser]
Cookie aint available till next server request? Means till i redirect to "dashboard" controller i cant access it right? But it doesnt redirect.

&
$this->access->login() is function from access.php application->library. Inside it i have set 'group_id' inside session varible so it should return something and not null.
M giving up code for login()

Code:
function login($username, $password)
{
  $result = $this->users_model->get_login_info($username);

  if ($result) // Result Found
  {  
   if (empty($result->active))
   {
    return 'BANNED';
   }
  
   if (!empty($result->verifystring))
   {
    return 'NOT_ACTIVATED';
   }
  

   $password = md5( $password); // Hash input password

   if ($password === $result->password) // Passwords match?
   {
    $this->CI->session->set_userdata(array('id'=> $result->user_id, 'group_id'=> $result->FK_group_id));

    return TRUE;
   }

  }
  
  return FALSE;
}
#14

[eluser]InsiteFX[/eluser]
As vbsaltydog stated most of your code is flawed!

Code:
if ($result) // Result Found

// should be
if ($result->num_rows() > 0)

All of your login method is totally wrong!

Old sayin garbage in garbage out
#15

[eluser]debasishdebs[/eluser]
Code:
function get_login_info($username)
{
  $this->db->select('password, email, user_id, FK_group_id, active');
  $this->db->where('username', $username);
  $i = $this->db->get($this->table);

  return $var = ($i->num_rows() > 0) ? $i->row() : FALSE;
}

This is my get_login_info() so ofcourse it returns correct thing. $this->table is name of table m accessing. If you say my login is wrong then what should i do? Use some authentication sys? Can you suggest a good one?
#16

[eluser]debasishdebs[/eluser]
Pls someone reply me.. What do i do? I want a forum to be merged with my existing auth sys.. Sad
#17

[eluser]vtx220[/eluser]
Look at forum bridges, but before you do that I would advise that you try looking through the documentation, read it all once so you can get familiar with certain keyterms and how codeigniter works and then resume by learning from codeigniter from scratch (nettuts). Once you get the basics understood, try looking at forum bridges and see if there's one for your forum. That's what I'd recommend, not sure what the veterans would Tongue

(I know it's not very helpful at first glance but it may be beneficial in the long run and you won't have to run around in circles like I have before.)




Theme © iAndrew 2016 - Forum software by © MyBB