• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic session Problem

#1
[eluser]ajay009ajay[/eluser]
I am facing very simple problem of session.How will i set session in CI.In general php we use..

$_SESSION['userid']=$uservalue;

I want to enable session for userid when he logged in.

What is the process to enable sesion in CI.Plz explain..

Thanx.

#2
[eluser]Dam1an[/eluser]
Have you read the sessions page in the user guide?

If so, you should have a pretty good idea, and if you still can't get it working, you can show us what you got so far, and what does/doesn't happen

#3
[eluser]ajay009ajay[/eluser]
Yes i read it properly and here is my implementation

if($query->num_rows() > 0 ){

$row = $query->row();
$id=$row->id;

$this->session->set_userdata($id); // Need to understand here //


$session_id = $this->session->userdata('session_id'); // Need to understand here

echo $session_id;
echo "aaaaaaaaaaaaaaaaaaaaaaaa";

}

I want to enable session when if statement will be true.
Am i doing ok?

#4
[eluser]n0xie[/eluser]
Code:
$this->session->set_userdata('session_id',$id);

#5
[eluser]kurucu[/eluser]
You're putting a session_id into the session, which is a bit confusing for me as I'd expect CI to manage that for you. On the other hand, I have no idea what your application is doing!

However, going on a very thin amount of information, I think the point that has been missed is that you can store any amount of information in the session, against a key that you decide. CI manages matching up the correct session with the correct user, timeouts etc.

So, as pointed out by n0xie, you need to specify a key with which to store the data (called 'session_id' here). You can create as many items as you like by calling this function several times with different keys.

Code:
$this->session->set_userdata('session_id',$id);
$this->session->set_userdata('username', 'Fred');

Then, as shown in your own code, you retrieve the data by passing the key to the userdata() function.

Code:
$session_id = $this->session->userdata(‘session_id’); // correct! $session_id will be $id from before
$username = $this->session->userdata(‘username’); // $username will be 'Fred'

Note: Cookies are small and, despite their limits, will affect speed and security of your website depending on what you put in them. If you want to store any data structures or important information then I'd recommend setting up DB storage, which is quite well explained in the user guide.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.