Jump to content

site was just working! now its not, sessions


ryanmetzler3

Recommended Posts

I have a website that runs using sessions. When the login page is submitted it starts a session and defines a username and user id. Then I have the following code pasted at the top of every page: 

session_save_path('/home/users/web/b2719/ipg.trackyourgraffiticom/cgi-bin/tmp');
session_start();
$username = $_SESSION['username'];
$userid = $_SESSION['userid'];

it was working fine and I did not change a thing but now when I log in, it logs me out immediately. So I did this:


session_save_path('/home/users/web/b2719/ipg.trackyourgraffiticom/cgi-bin/tmp');
session_start();
ini_set("display_errors", "1");
error_reporting(-1);
$username = $_SESSION['username'];
$userid = $_SESSION['userid'];
 

Just to see what errors came out. It says this: 

 

Notice: Undefined index: username in /hermes/bosoraweb068/b2719/ipg.trackyourgraffiticom/includelog.php on line 6 Notice: Undefined index: userid in /hermes/bosoraweb068/b2719/ipg.trackyourgraffiticom/includelog.php on line 7

 

 

Any ideas? because I can't figure out why that would make it not work.

What happens if you put session_start() before your session_save_path()?

 

session start is supposed to be the very first line in your file, but not sure if that counts in regards to another session setting.

 

If that's not the problem then you need to look at your login handler, specifically, where you're setting the username session variable. Make sure that's working.

 

Denno

  On 8/30/2013 at 10:59 AM, denno020 said:

What happens if you put session_start() before your session_save_path()?

 

session start is supposed to be the very first line in your file, but not sure if that counts in regards to another session setting.

 

If that's not the problem then you need to look at your login handler, specifically, where you're setting the username session variable. Make sure that's working.

 

Denno

 

From session_save_path

 

Session data path. If specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose.

 

Also, session_start isn't "supposed" to be the very first line in your file, although that is common practice, it just needs to be called before any output has been sent to the client.

 

@OP

 

Is there any reason you're modifying the session save path? Is the directory you're setting it to readable and writable by the user your server is running under? (probably www-data)

your code needs to have the display_errors/error_reporting settings as the first php statements so that if there are any errors when the session_save_path() and session_start() statements run you would know about them.

 

what is your code that is setting the $_SESSION variables? are you sure they are even being set in the first place?

  On 8/30/2013 at 12:07 PM, Andy-H said:

From session_save_path

 

Session data path. If specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose.

 

Also, session_start isn't "supposed" to be the very first line in your file, although that is common practice, it just needs to be called before any output has been sent to the client.

 

@OP

 

Is there any reason you're modifying the session save path? Is the directory you're setting it to readable and writable by the user your server is running under? (probably www-data)

Thanks for the suggestion. I modified the location because my server uses shared hosting. I did not really understand why but they said you need to change your session_save_path to a file in your directory to avoid problems. I got it working again. It was the strangest thing. I swear it was working fine and I did not change anything. Then it stopped working and I was messing with it for hours. Then I finally just reverted back to the original before I was about to go to bed and it works fine? Some kind of which craft for sure. 

  On 8/30/2013 at 12:44 PM, mac_gyver said:

your code needs to have the display_errors/error_reporting settings as the first php statements so that if there are any errors when the session_save_path() and session_start() statements run you would know about them.

 

what is your code that is setting the $_SESSION variables? are you sure they are even being set in the first place?

Thanks for the suggestion. It was the strangest thing. I swear it was working fine and I did not change anything. Then it stopped working and I was messing with it for hours. Then I finally just reverted back to the original before I was about to go to bed and it works fine? Some kind of which craft for sure. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.