Taha
Taha

Reputation: 651

Retriving $_SESSION data in codeigniter 2.1

I'm trying to retrieve session data and use it inside codeigniter, I have a php page having this code:

session_start(); 
$_SESSION['views']=1;

and when i want to retrive it in codeigniter page and it's in another folder using :

echo $_SESSION['views'];

or

echo $this->session->userdata('views');

Result is undefined. i'm using codeigniter 2 and also using this class.

https://bitbucket.org/Molchy/ndb-session-class-for-codeigniter/wiki/Home

and thanks.

Upvotes: 0

Views: 415

Answers (2)

웃웃웃웃웃
웃웃웃웃웃

Reputation: 11984

I think you have to use this in Codeignitor

To set

$this->session->userdata('views',1);

To get

echo $this->session->userdata('views');

If you are using php session then you do the following

To set

session_start(); 
$_SESSION['views']=1;

To get

echo $_SESSION['views'];

Upvotes: 0

Shomz
Shomz

Reputation: 37701

PHP's sessions ($_SESSION) and CI's sessions are not the same.

To set data to CI's session, simply do: $this->session->set_userdata('views', 1);

It's all very nicely documented: http://ellislab.com/codeigniter%20/user-guide/libraries/sessions.html

Upvotes: 1

Related Questions