Page 1 of 1

PHP Sessions Not Working with IIS

Posted: Mon Nov 17, 2008 5:45 pm
by nickka
I have everything up and running except sessions. I have an Eclipse development environment. I have Xdebug. But sessions variables after they are set are "uninitialized" the next time the code accesses it.

I am using Windows XP and IIS 5.1.

Re: PHP Sessions Not Working with IIS

Posted: Mon Nov 17, 2008 6:26 pm
by Syntac
Do you call session_start() at the beginning of your script?

Re: PHP Sessions Not Working with IIS

Posted: Mon Nov 17, 2008 7:08 pm
by Doug G
And make sure the IIS user account has write permissions to the directory you've set up for session storage.

Re: PHP Sessions Not Working with IIS

Posted: Tue Nov 18, 2008 9:09 am
by nickka
This is an open source web application that I am trying to get up and running. I see that session_start() is called in about 4 different locations in the code. In fact the session variable is being read after a session_start().

I see that sessions are being written to the configured location. I just want the session variables to be read after they are written.

Re: PHP Sessions Not Working with IIS

Posted: Wed Nov 19, 2008 8:45 am
by nickka
:banghead: anyone?

Re: PHP Sessions Not Working with IIS

Posted: Fri Nov 21, 2008 4:46 pm
by nickka
Here's some more information. I set a breakpoint where the session variable is set.

Code: Select all

session_register("authenticatedUser");
    $authenticatedUser = $_POST["username"];
authenticatedUser is set to "Admin".

I opened some of the sessions files. Some of these files are empty and others have:
authenticatedUser|N;

Apparently the sessions are not being written out properly. Any ideas on how to fix this?

Re: PHP Sessions Not Working with IIS

Posted: Fri Nov 21, 2008 5:09 pm
by VladSun
Save this as a PHP file. Browse to its address and refresh several times. Do you see incrementional numbers?

Code: Select all

<?php
session_start();
$_SESSION['i'] = isset($_SESSION['i']) ? $_SESSION['i'] + 1 : 1;
echo $_SESSION['i'];
?>

Re: PHP Sessions Not Working with IIS

Posted: Mon Nov 24, 2008 9:34 am
by nickka
Yes, the numbers do increment. It appears that sessions do work in this code. My code, however, is doing a session_register in one page and an isset in another page to read the sessions and it fails.

Re: PHP Sessions Not Working with IIS

Posted: Mon Nov 24, 2008 9:44 am
by VladSun
Read the Notes section in the manual:
http://bg.php.net/session_register

Re: PHP Sessions Not Working with IIS

Posted: Thu Dec 04, 2008 10:26 am
by nickka
I use $_SESSION['authenticatedUser'] = "xxx"; instead of session_register and now everything works.