Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/177636-session/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/177636-session/#findComment-936682
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/177636-session/#findComment-936718
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/177636-session/#findComment-936724
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/177636-session/#findComment-936753
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.