Share via


Session variables dissapear immediately

Question

Thursday, February 24, 2011 3:42 PM

I'm running IIS v7.5 on a Win7 development machine. I have PHP code that saves session variables and calls them back later. This has been working on this machine for some time.

For some reason now, the session variables dissapear immediatly after saving. Code that used to work fine on http://localhost/, suddenly now does not.

I have tested different browsers - the variables dissapear regardless of browser (IE, Firefox, Chrome, Opera).

I have tested session variables with both PHP and classic ASP. The variables dissapear regardless of language.

I have tested identical code on different servers. The problem exists only on this development machine.  The same code works just fine on other servers.

I tried some code that saves a session var, then reads it back and displays it, then shows a link to click on to read it back and display again. What happens is the session var DOES get written and read back and displayed ok. But when you click the link to view it again, it's gone.

I don't recall making any changes to IIS. But I did run several malware scanners and clean-up tools, but they all came up clean.

Is anyone aware of any setting in IIS that disallows session vars? Any other throughts?

All replies (9)

Monday, February 28, 2011 3:43 AM ✅Answered

Hello,

For this "I have tested session variables with both PHP and classic ASP. The variables dissapear regardless of language."

problem.

I suggest that you check account settings for IUSR,IIS_USRS having read,execute,list,write permissions

for the directory where sessions are stored.

I suggest that you check account settings for IUSR,IIS_USERS having read,execute,list,write permissions

for the C:\WIndows\Temp directory.

Look at your php.ini file settings for:  What directory your using and make sure accounts can write sessions as files.

Thank You,

Martin

 


Friday, February 25, 2011 6:42 AM

Session state may be disabled; session state may be moved out-of-process to an ASP.NET State Server or SQL Server database, which requires either the State Server service to be available on the network, or for the database to be installed, and the connectionstring configured. Also, are you using URL Rewriting? That can break cookies if the domain/host in the cookies being set doesn't match what the requesting browser things it is.


Friday, February 25, 2011 12:44 PM

Thanks for the tip.

But nope, session is set to In process.

Any other ideas?

The real problem is code on a site that is in production and working fine, but suddenly, after no code alteration, no longer saves session variables.

Below are the two pages I am using to test with:

 

PHPTest.php

 <?php
  session_start();
  error_reporting(E_ALL | E_STRICT);
?>

<form action="ViewSessionVars.php?GetStuff=foo&GetThings=bar" method="post">
  <input type="submit" name="PageAction" value="Okay">
</form>

<?php
$_SESSION["TestVar"]="One";
print "[".$_SESSION["TestVar"]."]<br>";
$_SESSION["TestVar"]="Two";
print "[".$_SESSION["TestVar"]."]<br>";
$_SESSION["TestVar"]="Three";
print "[".$_SESSION["TestVar"]."]<br><br>";
?>

<a href='ViewSessionVars.php'>View session variables</a>

 

ViewSessionVars.php

<?php
  session_start();
  error_reporting(E_ALL | E_STRICT);
?>

<html>
  <head>
  </head>
  <body>

<?php

  print "<a href='ChooseSite.php'>« Back to ChooseSite.php</a>";
  print "<br><br><br>";

  print "<b>VIEW SESSION AND HEADER INFORMATION</b><br/>";
 
    print "<br/>";
    print "SESSION=============================<br/>";
      foreach($_SESSION as $key=>$value) {
        print $key." = ".$value."<br/>";
      }
       print "<br/>";
      
    print "GET=================================<br/>";
      foreach($_GET as $key=>$value) {
        print $key." = ".$value."<br/>";
      }
       print "<br/>";

    print "POST================================<br/>";
      foreach($_POST as $key=>$value) {
        print $key." = ".$value."<br/>";
      }
       print "<br/>";

    print "SERVER==============================<br/>";
       foreach($_SERVER as $h=>$v)
         if(ereg('HTTP_(.+)',$h,$hp))
           echo "<li>$h = $v</li>\n";
       header('Content-type: text/html');
       print "<br/>";
    print "====================================<br/>";

?>

  </body>
</html>


Sunday, February 27, 2011 8:46 PM

I just uninstalled / reinstalled IIS.  I thought this would take care of the problem, but no.

So either some settings are still around from the previous IIS install (which I doubt), or the problem is caused by something other than IIS.  However I have no idea what that might be.

 


Monday, February 28, 2011 4:03 AM

Hi,

What is your PHP version?

"PHP 5.2.2 introduced an undocumented feature to store session files in "/tmp" even if open_basedir was enabled and "/tmp" is not explicitly added to the allowed paths list. This feature has been removed from PHP as of PHP 5.3.0. "

Also, you can print the session id to see if it  was changed between pages.


Monday, February 28, 2011 9:37 AM

Thanks for the suggstion Leo.

I added code to show the session id, and it's the same from page to page.  I though for sure I'd find it was changing, but no.  So now, that's even more strange.

My PHP is 5.3.3.

 Everyone... anyone.... I am open to any suggestions you may have.  Oddly enough I haven't found anyone with this problem yet.

 


Monday, February 28, 2011 12:39 PM

Hello,

One of the troubleshooting problems is where the error

information will be found for server side code.

The client / browser gets little or no information but errors are logged for execution & failures.

I suggest that you check the web server log and post to the Forum

errors & messages during the session code execution.

I suggest that you get and install Processor Monitor from system internals

to monitor what is occuring during the session code it may provide more insights.

Thanks,

Martin

 


Monday, February 28, 2011 1:57 PM

Thanks Martin.

Once we re-read your post, it was clear we were only fixing permissions for the user IUSR, not also IIS_USRS.  Once we changed permissions exactly as you state, the problem was fixed!!!!

Thank you so much !!!


Monday, February 28, 2011 4:20 PM

Hello,

Glad you got it resolved.

If the question is answered please mark the Thread Answered.

Thank You,

Martin