bnt Posted March 3, 2009 Share Posted March 3, 2009 ??? I just started having a problem with $_SESSION. I start each script with <?php session_start(); ?> as the top line. I use the standard $_SESSION['abc']=123 format. Everything has been working perfect ... until just recently. Now when I move from one script to another, the information stored in ALL SESSION VARIABLES disappears!!! I am running PHP ver 5.1.6. ANY HELP WOULD BE GREATLY APPRECIATED!!! I am somewhat new to PHP and have no idea how to proceed... It is not limited to a single script... ALL of my scripts are having the same issues with the SESSION variables disappearing. Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/ Share on other sites More sharing options...
fry2010 Posted March 3, 2009 Share Posted March 3, 2009 I had a similair problem before... Firstly have you turned on error reporting for php in the .ini file? Second have you changed anything since it stopped working? if so what? Have you re-installed php at all? This was my problem I did a manual install of it and didnt point the directory for storing sessions in the .ini file. So check the path for sessions in your .ini file. Make sure you have no white space before <?php and after ?>, and between <?php session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775755 Share on other sites More sharing options...
bnt Posted March 3, 2009 Author Share Posted March 3, 2009 I looked at my phpinfo and cannot see where or how the path is set for sessions in php.ini. Can you tell me what directives I should be looking for? I am using a shared hosting server so I cannot re-install PHP I have not changed anything in the php.ini file that could make it stop working. I set safe mode to off but that should have no effect. Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775759 Share on other sites More sharing options...
revraz Posted March 3, 2009 Share Posted March 3, 2009 You want to look for the session save path in the php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775797 Share on other sites More sharing options...
bnt Posted March 3, 2009 Author Share Posted March 3, 2009 My phpinfo does NOT contain any directives containing the word SESSION much less session_save_path. Should this be in there? Where should the save path be set to (if it was there)? I started trying to write a cookie and then read it. That does not work either! In fact, after using setcookie("abc",123) I should be able to view the cookie fin the browser... lot's of cookies but not this one! Something very weird is going on. What course of action should I take?? Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775806 Share on other sites More sharing options...
premiso Posted March 3, 2009 Share Posted March 3, 2009 Your setcookie is wrong. You can try using .htaccess or even ini_set to set the session save. But if your host has sessions disabled, then yea. You have no control over that. Check the phpinfo and see if there is a section called "SESSIONS" that states "disabled" under it. Sessions should be default on most php builds unless they turned it off. Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775822 Share on other sites More sharing options...
bnt Posted March 3, 2009 Author Share Posted March 3, 2009 I ran the following script... <?php echo ini_get('session.cookie_path'); echo "<br>".ini_get('session.name'); echo "<br>".ini_get('session.use_cookies'); echo "<br>".ini_get('session.save_path'); echo "<br>".ini_get('session.save_handler'); ?> and got the following output... / PHPSESSID 1 /var/lib/php/session files Based on this, it appears that SESSION is set and active??? Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775826 Share on other sites More sharing options...
PFMaBiSmAd Posted March 3, 2009 Share Posted March 3, 2009 Sounds like a header issue and that output buffering might have been on in php.ini and has been turned off. Add the following two lines immediately after your first opening <?php tag on any page you are setting or referencing a session variable or on your page where you are attempting to use setcookie() - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775828 Share on other sites More sharing options...
bnt Posted March 3, 2009 Author Share Posted March 3, 2009 I have two very simple scripts to test this out... test99.php... <?php session_start(); ?> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); include_once "functions.php"; $_SESSION['abc']=4444; jumpto1('test100.php'); // jumpto1 is a function that is a few javascript lines that redirects the browser... ?> and test100.php... <?php session_start(); ?> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); print_r($_SESSION); die(); echo ini_get('session.cookie_path'); echo "<br>".ini_get('session.name'); echo "<br>".ini_get('session.use_cookies'); echo "<br>".ini_get('session.save_path'); echo "<br>".ini_get('output_buffering'); ?> the output is... Array ( ) Warning: Unknown: open(/var/lib/php/session/sess_is7n6l58jfuelf2t172cahnto5, O_RDWR) failed: Permission denied (13) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0 ////////////////////////////////////////// session.save_path is set to /var/lib/php/session Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775853 Share on other sites More sharing options...
fry2010 Posted March 3, 2009 Share Posted March 3, 2009 on your part where you put this: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); print_r($_SESSION); die(); you need to change the $_SESSION to $_SESSION['abc']. Also in your .ini file check this: ; Whether to use cookies. session.use_cookies = 1 and ; Name of the session (used as cookie name). session.name = PHPSESSID If this fails to work, you could try turning on automatic sessions with this in the .ini file: ; Initialize session on request startup. session.auto_start = 1 If it works when you do this then there is probably error with your code. remember to re-start apache. check this too: ; Handler used to store/retrieve data. session.save_handler = files Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775873 Share on other sites More sharing options...
PFMaBiSmAd Posted March 3, 2009 Share Posted March 3, 2009 From the error - Permission denied The permissions on /var/lib/php/session/ are not set correctly to allow php to create the session data files. Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775876 Share on other sites More sharing options...
bnt Posted March 3, 2009 Author Share Posted March 3, 2009 How would I change the permissions of directory /var/lib/php/session ???? I have used putty but am a bigtime newbie!! Any detailed help would be VERY MUCH appreciated... Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775895 Share on other sites More sharing options...
premiso Posted March 3, 2009 Share Posted March 3, 2009 Why not just change the session.save_path to be within your own directories then make that directory be protected by you. This is preferred especially on a shared host. You should be able to use .htaccess to change where the session saves the data at. Quote Link to comment https://forums.phpfreaks.com/topic/147785-problem-with-_session/#findComment-775897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.