I've an issue where session_start() hangs.
I've tried replacing the "file" method with "memcached". This did not correct the problem.
The problem is not concurrent access. It's not that I'm trying to access an session with two separate scripts at the same time.
I can create the session and save it, but cannot access the session afterwards.
Checking in my session.save_path, I can see that the session file was created, and I don't see any problem with it.
Here is an example session file:
sess_88senr7p8icjaiebup8i449l41:csrf|s:32:"401a0f9028b00102c671459da8537286";userdata|a:6:{s:2:"id";s:4:"3198";s:5:"email";s:25:"paul#*******.com";s:4:"name";s:17:"********";s:6:"parent";s:4:"3198";s:11:"permissions";i:1;s:15:"app_permissions";N;}employer|a:8:{s:2:"id";s:4:"3198";s:12:"company_name";s:7:"**";s:21:"user_accounts_allowed";i:20;s:18:"user_accounts_used";i:20;s:5:"notes";s:0:"";s:14:"contract_start";s:10:"2013-04-10";s:12:"contract_end";s:10:"2014-04-10";s:8:"features";i:2;}
This is acting as if the session lock is simply not removed at all. Where would I check to find this? Would this same issue affect "file" and "memcached"?
Related
I didn't change any code, all of a sudden when I visited one of the webpages, I see
Warning: session_start() [function.session-start]: open(..)Failed: File too large .. index.php on line 2.
Another error is:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent`
Line1 : <?php
Line2 : session_start ();
Questions:
what is the reason for error that tells File too large? what file is large?
why all-of a sudden there is an error without any file modification being done?
why it is throwing 'headers already sent', when there is nothing defined before session_start, not even a space ?
How to fix this issue?
1. what is the reason for error that tells File too large? what file is large?
This seems to be the hosting provider issue, as the original file was never modified, and the webpage has been tried from multiple browsers even after clearing the cache.
When you do session_save_path("../_session1001"); that is mentioned below, you can see that your session is written to that path, so may be that this file was becoming too large in your shared memory,and now that I explicitly mentioned a physical space to write the session files to, this error is no more.
4. How to fix this issue?
Create a directory named say '_session1001' and give chmod 755 so your webserver (app) can write to it.
Add this line before session_start
session_save_path("../_session1001");
Ensure you protect the directory via .htaccess file.
ie:
<?php
session_save_path("../_session1001");
session_start();
Read more here : http://php.net/session_save_path
Note:
Debian does not use the default garbage collector for sessions. Instead, it sets session.gc_probability to zero and it runs a cron job to clean up old session data in the default directory.
As a result, if your site sets a custom location with session_save_path() you also need to set a value for session.gc_probability,
e.g.:
<?php
session_save_path('/home/example.com/sessions');
ini_set('session.gc_probability', 1);
?>
Otherwise, old files in '/home/example.com/sessions' will never get removed!
The problem is that every time I refresh the page or when I change the page to another one, the session_id changes and new session file is created in session_save_path.
Here is the initial part of my code:
<?php
session_start();
echo session_id();
...
?>
Obviously the session variables (which is the thing that I need) don't work.
A curious thing is that the page works fine on localhost but doesn't work when I try it on the server.
Thanks in advance.
Check this setting in your server: session.auto_start
This will cause session to be autostarted in each page whether you call session_start() or not.
Make sure that there are no phantom CRLFs or such stuff before session starts. In production the error_reporting can be off so it might not get caught, but the session might find difficulty getting written. This can sometimes cause this.
On your server, in php.ini check TTL for your cookies. session.cookie_lifetime defines how long the cookie will last in seconds (default is 0, which means until the browser is closed) and session.gc_maxlifetime defines how long before the data is deleted, also in seconds.
And make sure the session file isn't stored in a /tmp folder.
Looks like your directory with sessions is not writable.
That's why php generates a new session file each time.
Check your chmod for sessions folder.
I'm unable to get any session data to persist across my app. I'm using a cart package and after adding the items the cart is immediately empty when I try to retrieve the data in another page.
I've tested the session by creating a test session and then retrieving that. It works if I retrieve it immediately but if I call the session on another page it no longer works
I've read similar threads and have my session config file set as:
driver => native
lifetime => 120
expire_on_close => true
domain => false`
There's no output ie echo statements before redirects. I've tried doing a fresh install but still the same problems. This is currently on a local server - localhost with a url of test.loc
This can happen if PHP is trying to save to a path that is not writable/doesn't exist.
Try the following code to check where PHP is trying to save session files:
<?php
echo ini_get('session.save_path');
?>
Then check that folder to see if a) it exists and b) if session files are being written into it.
If it doesn't exist you need to change the .ini file or use ini_set('session.save_path') to change where PHP is trying to save session info. If the folder does exist it may be a permissions issue.
Finally, it may be a cookie issue - try using the app with different browsers, and check that the browsers have cookies enabled.
I am accessing my website from Linux server. At the time of user login I create session.
But Even I didn't open site and locate in folder /var/lib/php/session
there are contentiously some session file are getting created.
I am unable to find from where these files are getting created.
A session is always created. Your login just assigns the session with an user and the information that he/she/it is authenticated.
Note: Also search engines and robots create sessions on your page.
PHP creates sessions whenever you call session_start()
After to much research I found that session were getting created from cron files.
I removed session_start call from cron files.
I have two scripts on the same domain.
www.xxx.com/first/
www.xxx.com/second/
I have register_globals=on, I've checked the spelling multiple times. I've checked session_save_path() and they both are working on the same directory.
I even tried setting session_save_path to a new directory just in case.
Each script is accessing a session independently. If I set the value of a session variable in one script, it stays. If I set the value of it in the other script it stays. Neither of the scripts are updating the other, so they must be writing their own sessions. I'm using the same browser without any security.
Any ideas to what would make these talk?
Thanks!
UPDATE!
Found out that one of the scripts was defining a session_name variable. Make sure that these are the same.
Thanks for all your help anyways!