Access cakephp (auth) session from outside cakephp

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

A user is logged in and is browsing a website. At some point, he may click the link that opens the external php file. From the outside, I mean that it can be in a different folder of the same server, but outside of CakePHP application folders.

The “tricky” thing (for me) is to show the contents of this php file only if the user is logged in (so that someone who does not have an account does not access such contents). I can’t use Auth there because I am "outside" Cake ... I don’t know, maybe using $ _SESSION, but I don’t know how ...

Is it possible? And yes, php must be outside the CakePHP application folder system.

Any ideas?

+6
source share
3 answers

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

$_SESSION['Auth'] 

if it exists then check user here

 $_SESSION['Auth']['User'] 
+7
source

I will add, you also need to set the session name to "CAKEPHP" using

 session_name('CAKEPHP') 

before your external application session_start () otherwise you could not apply the solution proposed by Kashif Khan :)

Greetings

+8
source

This does not work in Cakephp3. After the call

 session_name("CAKEPHP"); session_start(); 

The duration of the application session.

+1
source

Source: https://habr.com/ru/post/904406/


All Articles