Jump to content

[SOLVED] All of a sudden my Session variables get dropped


Craig79

Recommended Posts

Hello,

I installed PHP5, Apache2, and MySql5 on Ubuntu Linux 8.10. I use this script to verify that someone has been verified from a previous page:

 

if ((isset($SESSION[sesone])) && (isset($SESSION[sestwo]))) {

  // the user was validated on a previous page

} else {

    // they have not been validated on the previous page

}

 

I checked the output of the session variables on the page that set them by echoing them out after they had been set. That works. I used this to set the variables:

$SESSION[sesone] = $myvarBut when I redirect to another page, the session variables are empty. What happened?

 

This works on one of my sites running PHP 4.3. Is that the difference?

 

Other info:

---------------------------------------

every page begins with session_start();

Session support: enabled

session.use_cookies: on

register_globals: off

Link to comment
Share on other sites

Add the following two lines immediately after your first opening <?php tag (and before the session_start()) on both the page where you set the session variable and on the page where you are trying to use the session variable -

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
Share on other sites

Thank you - that indeed does look helpful.

 

Here's what I got:

 

Notice: Use of undefined constant sesone - assumed 'sesone' in /var/www/fitness/createtasks.php on line 25

Notice: Undefined index: sesone in /var/www/fitness/createtasks.php on line 25

 

Notice: Use of undefined constant sestwo - assumed 'sestwo' in /var/www/fitness/createtasks.php on line 25

Notice: Undefined index: sestwo in /var/www/fitness/createtasks.php on line 25

 

My note:

Line 25 has this:

echo 'sesone is ' . $_SESSION[sesone] . ' and sestwo is ' . $_SESSION[sestwo] . '<br>';

 

Link to comment
Share on other sites

Those two error message are telling two things -

 

1) The proper syntax is (missing quotes on associative array index names) -

 

echo 'sesone is ' . $_SESSION['sesone'] . ' and sestwo is ' . $_SESSION['sestwo'] . '<br>';

 

2) Whatever page that is, the session variables don't exist. Either they were not set, the session id was not propagated between pages by the browser, or the session variables got overwritten by your code or by register_globals.

 

Is the setting you show for register_globals from a php.ini setting or from the actual value that a phpinfo() statement shows?

Link to comment
Share on other sites

Thank you very much: it's getting better. With the single quotes, I now get:

 

Notice: Undefined index: sesone in /var/www/fitness/createtasks.php on line 25

Notice: Undefined index: sestwo in /var/www/fitness/createtasks.php on line 25

 

...instead of...

 

Notice: Use of undefined constant sesone - assumed 'sesone' in /var/www/fitness/createtasks.php on line 25

Notice: Undefined index: sesone in /var/www/fitness/createtasks.php on line 25

Notice: Use of undefined constant sestwo - assumed 'sestwo' in /var/www/fitness/createtasks.php on line 25

Notice: Undefined index: sestwo in /var/www/fitness/createtasks.php on line 25

 

Odd how the quotes never mattered before, but I'm just greatful to find the fix. Now the only thing that remains is the Undefined Index

 

Yes, the variables I posted were from the output of phpinfo()

Link to comment
Share on other sites

That leaves - Either the session variables were not set, the session id was not propagated between pages by the browser, or the session variables got overwritten by your code. There is probably another possibility - the session data file is being deleted on every session_start() statement.

 

Start checking on your server and in your browser to determine which of these things are occurring or not. Is the session data file getting created and does it remain for a while. Is the session id cookie present in the browser? Did this problem correspond to a change in your code and you would need to post both the code that sets the session and the code that uses the session  for anyone in a forum to help with what they might be doing to cause this symptom.

 

BTW: These errors - Use of undefined constant sesone - assumed 'sesone' in ... were always occurring with that code but the error reporting settings were hiding them. However, php make as assumption (stated in the error message) so the code functions, but it take 10-20 times longer for each line of code with that error in it to be executed because of the error response logic php goes through to try to find first a constant by that name and then look up an actual array index by that name.

Link to comment
Share on other sites

Thank you  - I'll troubleshoot these.

 

As for the 'sesone' session variable, I don't think it's not occuring on my other site due to the error reporting being off. If the variable was not passed and verified, this would mean that the user is not authenticated and they would be given an error display. I've tested it dozens of times with different user accounts, in IE and FireFox, and they all work.

 

The only difference is that this instance is running on a different platform: Ubuntu 8.10. On IIS and CentOS I have had no problems.

 

I did check the session file and i did NOT see a session id in it. What could that be? It just had session names and variables, and the correct value for the variables were there. I'm completely puzzled.

 

Also, I've tried these, but they didn't work:

--------------------------------------------

 

session_commit() before redirecting to new page

 

changed the session.save_path to a directory with complete read/write privileges (I restarted Apache after making changes to the php.ini)

Link to comment
Share on other sites

Some possibilities associated with the browser not passing the session id between pages would be if the pages had different host names/subdomain or had different paths and the session cookie settings where not setup to allow the session cookie to be passed between these. Do the URL's of the two pages have different host names/subdomains, like www.yourdomain.com and just yourdomain.com and/or yourdomain.com/somepath/file1.php and yourdomain.com/someotherpath/file2.php?

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.