Access Symfony2 session from another php file? - session

I want to access symfony session data from another php page, based in web directory.
I've defined:
$this->getRequest()->getSession()->set('school', 'abc');
And want to get('school') in another php paged existed in web directory (not a controller). I've searched Google for hours and tried lots of alternatives but couldn't be success.

I've solved this problem with this solution:
In config.yml:
framework:
session:
save_path: ~
Then I started a session_start(); in a plain php script.
And accessed via:
$_SESSION['_sf2_attributes']['my_value'];
Now, it's ok.

Related

File session driver not working properly on production (Laravel on shared hosting)

When using session on my local environment all worked ok, but when I publish the site in a shared hosting I started noticing some strange behaviours in the app. After a while I realized it has to do with the session and specifically I noticed that when I was working on my local environment the storage/framework/sessions folder only had 1 file that keep updating on any change but then on production I start monitoring the same folder and I realized that on any change instead of updating the file (or creating a new one and deleting the other) it was creating a new file but also keeping the old files making the app start acting in a wrong way.
Is this normal or should it be only 1 file per session as it was in the local environment?
Update
After login the user the app ask to select the business they want to work and also they can change between business after, to store the business they choose I use the session and there is where the problem pop, after every change on that property of the session it creates a new session file without deleting the old one. Again when I do exactly the same thing locally it works but for some reason on the shared hosting it doesn't.
SOLUTION
After days of trying to figure it out, I just figure out the solution.
Instead of using the Global Helpers of Laravel for storing the data I did it throw the request and apparently that work it out.
So basically instead of doing this:
session('clienteElegido' => $client);
I change it for this:
$request->session()->put('clienteElegido',$client);
I still don't understand what's the difference and why it was working fine in my local environment and not in the share host but its working now like that so all good.
Thank you for all the quick replies.
Try clearning cache, route, config and view
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
and let's see if your session issue will be fixed.

Session laravel 5.3 not working over LAN

currently using :
laravel 5.3
session driver already tried memcached,redis
my session data each refresh page it's always gone..
when i try using php artisan serve, it's normal not gone at all.. but when accessing from LAN.. it's look like no even stored at all..
i try using virtual host on my fedora but it's normal..
just because of accessing from LAN why my session can't stored at all?
is somebody experience something like this?
just scare if i up this app.. and this problem show up..
here's part of my login controler that stored email and token
$req->session()->put('USER_TOKEN',$data->token);
$req->session()->put('USER_EMAIL',$result->param["email"]);
for get the session value in my home controoler
$req->session()->get('USER_TOKEN');
$req->session()->get('USER_EMAIL');
best regards,

Set Laravel Application Urls

Fairly new to Laravel here and I'm struggling to understand how to make Laravel 5.2 aware of where it resides. Here's the issue:
I set up auth using php artisan make:auth, and can now see the lovely landing page, as well as login and register links in the menu. The problem is that these links don't go to the right place. They point to /login and /register in the code respectively, which translates into http://localhost/login or http://localhost/register. But since I'm not on a production site yet and am developing locally, my website resides at http://localhost/projectname/public.
I've gone into config/app.php and tried various values for the URL parameter, but these have no effect.
What can I do to get these links to reflect the full site URL, without manually entering it each time?
you can run the development server in laravel using this command
php artisan serve
Did you try that?
Use laravel url function:
{{ url().'/login' }}

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?
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,
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']
This is not working in Cakephp3. After calling
session_name("CAKEPHP");
session_start();
Application session is expiring.

Symfony2 dev environment not clearing cache automatically

I'm working on a new Symfony2 project, and I'm using the app_dev frontcontroller to view the default AcmeDemoBundle's pages.
When I make changes to the controllers, I get an exception (NotFoundHttpException: No route found for "GET /demo/hello/World"). If I clear the cache using php app/console cache:clear, things work great again. However, it is my understanding that by using the app_dev front controller, I shouldn't be required to do this. Am I doing something wrong?
Soms system specs:
OSX Lion using MAMP
PHP 5.3.6
Symfony 2.0.1
Are you using different users for webserver and command line user? Maybe you should check for permissions in the Setting up Permissions paragraph.

Resources