6
votes

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?

3
var_dump or print_r are very useful php functions. Use them with $_SESSION and you can see everything CakePHP does with it. It's actually interesting to look at.Vigrond
I had the same question a while ago: stackoverflow.com/questions/6988156/…AlexBrand

3 Answers

8
votes

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,

7
votes

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']
1
votes

This is not working in Cakephp3. After calling

session_name("CAKEPHP");
session_start();

Application session is expiring.