resullivan Posted October 14, 2009 Share Posted October 14, 2009 I am having a little trouble with a session. Not sure if it is my browser or what. I know I do not have any trouble logging into forums such at these, so not sure why this is not working. first the code. Just basic code from php documentation plus some added checks. <?php // page1.php if (session_start()) { echo "OK"; } else { echo "FAIL"; } // echo phpinfo(); // echo getcwd(); echo 'Welcome to page #1'; $_SESSION['favcolor'] = 'green'; $_SESSION['animal'] = 'cat'; $_SESSION['time'] = time(); print_r($_SESSION); // Works if session cookie was accepted echo '<br /><a href="page2.php">page 2</a>'; // Or maybe pass along the session id, if needed echo '<br /><a href="page2.php?' . SID . '">page 2</a>'; ?> And <?php // page2.php session_start(); echo 'Welcome to page #2<br />'; echo $_SESSION['favcolor']; // green echo $_SESSION['animal']; // cat echo date('Y m d H:i:s', $_SESSION['time']); print_r($_SESSION); // You may want to use SID here, like we did in page1.php echo '<br /><a href="page1.php">page 1</a>'; ?> There is no reason why this should not work. Can someone go to: http://www.e-sullivan.com/DIITop25/page1.php and tell me if it works for you? It shows me that the sessions are being started but the variables are not passing between page1.php and page2.php for me. Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2009 Share Posted October 14, 2009 Add the following two lines of code immediately after the first opening <?php tag on both pages - ini_set("display_errors", "1"); error_reporting(E_ALL); And what version of php, because session_start() only returns a valid true/false value on php5.3 Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936682 Share on other sites More sharing options...
resullivan Posted October 14, 2009 Author Share Posted October 14, 2009 Warning: session_start() function.session-start: open(/var/php_sessions/sess_87edcef65ecc05b6200c1cff5bb84c9b, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web002/b20/glo.resullivan/DIITop25/page1.php on line 6 I think I saw an old post where someone had said they had this problem and it ended up being because their host had switch servers and the /var/php_sessions/ no longer existed. Looks like I may have the same problem. Do you I need to contact my host or is there something else wrong? Let me say this also. I have a phpbb board on one of my sites and the login seems to work for it. Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936718 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2009 Share Posted October 14, 2009 At the time your script executes, session.save_path is set to /var/php_sessions/. That is either the correct setting but the path does not exist, or it is an incorrect setting and should in fact be changed to point to the correct folder. If you are on shared web hosting, you should actually have a 'private' folder within your account's folder tree and set session.save_path to point to that folder. The folder should be outside your document root folder (closer to the disk root) so that no one can attempt to browse to the session data files. If that option is not available and you can only put the folder within your document root folder, you need to put a .htaccess file in the folder that prevents (deny) all http requests. Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936724 Share on other sites More sharing options...
resullivan Posted October 14, 2009 Author Share Posted October 14, 2009 What I did was added a local php.ini file and set that to a directory that exists. Now I have two questions. 1. Will this local php.ini file will only affect the php files in this directory? 2. Why does my phpbb board work? Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936748 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2009 Share Posted October 14, 2009 1. Will this local php.ini file will only affect the php files in this directory?It should apply to the whole site, but this depends on how the host has setup the server. Some configurations require a local php.ini to be placed in each folder you want it to affect. 2. Why does my phpbb board work? I have a phpbb board on one of my sites Yes, but is it on the same server as the one you are currently having a session problem? Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936753 Share on other sites More sharing options...
resullivan Posted October 14, 2009 Author Share Posted October 14, 2009 yes it is on the same server. Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936756 Share on other sites More sharing options...
resullivan Posted October 14, 2009 Author Share Posted October 14, 2009 I answered one of my questions. I do have to put a php.ini file for each folder. I also created a tmp folder (I do not have access below root) and added a .htaccess file with the following line: Deny from all Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936763 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2009 Share Posted October 14, 2009 phpbb (at least V3) does not use php's built in sessions. It completely manages the propagation of variables between pages using php code and it stores the data in a database table. Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936765 Share on other sites More sharing options...
resullivan Posted October 14, 2009 Author Share Posted October 14, 2009 Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/177636-session/#findComment-936769 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.