happyhardik
happyhardik

Reputation: 25567

how to get $_SESSION value in cakephp

I am setting up a user session from a core php app that is located in example.com/corephp/, now I want to redirect this user to example.com (the main site) which is in cakephp.

How can I retain the user session from the core php app to cakephp app?

I triend setting $_SESSION['user'] = someone and $_SESSION['token'] = token from core php app and tried to retrieve that value from cakephp but it didn't work.

I tried to google for this but no proper answer that could work.

Thanks in advance.

---------------------- edit

I have tried adding session_name('CAKEPHP'); to the core php app. As well as tried to reduce the security level of my cake app from medium to low.

Upvotes: 5

Views: 4014

Answers (2)

mark
mark

Reputation: 21743

Always use the session wrappers. thats what they are there for

in the controller: http://book.cakephp.org/2.0/en/controllers/components.html#using-components

in the view: http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html

everywhere else: http://book.cakephp.org/2.0/en/development/sessions.html#reading-writing-session-data

never ever access it using $_SESSION and you should be fine (cake inits the session for you and takes care of a lot of things behind the hood).

if you share the session make sure you set the session name equally. both should also use the same session type (php probably).

Upvotes: 0

stan
stan

Reputation: 4995

Didn't test, but try this.

In your corephp app:

$_SESSION['Auth']['User'] = $someone;

My reasoning is that it will set the $_SESSION, but maybe CakePHP doesn't recognize it for some reason. So we set it the right way using Cake's API:

In CakePHP

$this->Session->write('Auth.User', $_SESSION['Auth']['User']);

Upvotes: 2

Related Questions