Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access cakephp session (auth) from outside cakephp

I have a CakePHP website with its own login system using the Auth component. I would like to know if the following is possible:

A user has logged in and is navigating the website. At one point, he can click a link that opens an external php file. With external I mean that it could be in another folder of the same server, but outside the CakePHP app folders.

The "tricky" thing (for me) is to only show the contents of that php file if the user is logged in (to prevent someone without an account accessing those contents). I can't use Auth there because I'm "outside" Cake... I don't know if maybe using $_SESSION, but I don't know how...

Is this even possible? And yes, the php has to be outside the CakePHP app folder system.

Any ideas?

like image 580
Albert Avatar asked Dec 23 '11 19:12

Albert


2 Answers

I'll add you also need to set session name to "CAKEPHP" using

session_name('CAKEPHP')

just before your external app session_start() otherwise you could not apply Kashif Khan suggested solution :)

Cheers,

like image 60
Clément Legrand Avatar answered Sep 18 '22 01:09

Clément Legrand


Yes you can access the cakephp SESSION outside cakephp folder. try this session variable

$_SESSION['Auth']

if it exists then check for user here

$_SESSION['Auth']['User']
like image 29
Kashif Khan Avatar answered Sep 19 '22 01:09

Kashif Khan