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.

Edited by ryanmetzler3
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Edited by Andy-H
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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. 

Link to comment
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.