Yes, I have tried to set a $_SESSION variable within Laravel and read it back in the external PHP, but that didn't work. The external PHP is Responsive FileManager. I'm trying to pass a Laravel username to it so I can have it set a home directory path for each user as in the documented $_SESSION["RF"]["subfolder"] ="subfolder/name/"
Any ideas?
Thanks @slayerfat for the suggestion, but I tried setting both $_GLOBAL['my_var'] and $GLOBALS['my_var'] without any success. I am still unable to access my variable from outside of Laravel.
Surely, there must be a way to read the variable. Am I overlooking something?
Ok, after toying around I found that the session path was not on my web root. Once I set the path to "/", I was able to read the session variable outside of Laravel. Here is my example
/*
Set regular PHP cookie from within Laravel
Notice the fourth parameter set to /
*/
setcookie("current_user", Auth::user()->username,0,"/");
Now on my external file I can access the variable as follows:
// Read cookie as expected:
echo $_COOKIE['current_user']
This seems to work, but I will test a little bit more. There may be a better, more secure way. If anyone has a better suggestion, please let me know!
Update: I recommend you add a little bit of encryption/decryption when storing/retrieving cookie data and this works well.. I will mark it as a solution in hopes that it helps others.
use:
<?php session_start(); $_SESSION["RF"]["subfolder"] = "folder_user1" //subfolder of your user ?>It's 2016, but for anyone having this problem:
This might help you out. :)
[https://bgtsworks.blogspot.com/2016/08/access-laravel-session-outside-laravel.html]
djtechonline said:
Ok, after toying around I found that the session path was not on my web root. Once I set the path to "/", I was able to read the session variable outside of Laravel. Here is my example
/* Set regular PHP cookie from within Laravel Notice the fourth parameter set to / */ setcookie("current_user", Auth::user()->username,0,"/");Now on my external file I can access the variable as follows:
// Read cookie as expected: echo $_COOKIE['current_user']This seems to work, but I will test a little bit more. There may be a better, more secure way. If anyone has a better suggestion, please let me know!
Update: I recommend you add a little bit of encryption/decryption when storing/retrieving cookie data and this works well.. I will mark it as a solution in hopes that it helps others.>djtechonline said:
Ok, after toying around I found that the session path was not on my web root. Once I set the path to "/", I was able to read the session variable outside of Laravel. Here is my example
/* Set regular PHP cookie from within Laravel Notice the fourth parameter set to / */ setcookie("current_user", Auth::user()->username,0,"/");Now on my external file I can access the variable as follows:
// Read cookie as expected: echo $_COOKIE['current_user']This seems to work, but I will test a little bit more. There may be a better, more secure way. If anyone has a better suggestion, please let me know!
Update: I recommend you add a little bit of encryption/decryption when storing/retrieving cookie data and this works well.. I will mark it as a solution in hopes that it helps others.
Appreciate your work djtechonline
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.