PHP Sessions Not Working with IIS

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
nickka
Forum Newbie
Posts: 10
Joined: Mon Nov 17, 2008 5:40 pm

PHP Sessions Not Working with IIS

Post 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.
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: PHP Sessions Not Working with IIS

Post by Syntac »

Do you call session_start() at the beginning of your script?
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: PHP Sessions Not Working with IIS

Post by Doug G »

And make sure the IIS user account has write permissions to the directory you've set up for session storage.
nickka
Forum Newbie
Posts: 10
Joined: Mon Nov 17, 2008 5:40 pm

Re: PHP Sessions Not Working with IIS

Post 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.
nickka
Forum Newbie
Posts: 10
Joined: Mon Nov 17, 2008 5:40 pm

Re: PHP Sessions Not Working with IIS

Post by nickka »

:banghead: anyone?
nickka
Forum Newbie
Posts: 10
Joined: Mon Nov 17, 2008 5:40 pm

Re: PHP Sessions Not Working with IIS

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP Sessions Not Working with IIS

Post 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'];
?>
There are 10 types of people in this world, those who understand binary and those who don't
nickka
Forum Newbie
Posts: 10
Joined: Mon Nov 17, 2008 5:40 pm

Re: PHP Sessions Not Working with IIS

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP Sessions Not Working with IIS

Post by VladSun »

Read the Notes section in the manual:
http://bg.php.net/session_register
There are 10 types of people in this world, those who understand binary and those who don't
nickka
Forum Newbie
Posts: 10
Joined: Mon Nov 17, 2008 5:40 pm

Re: PHP Sessions Not Working with IIS

Post by nickka »

I use $_SESSION['authenticatedUser'] = "xxx"; instead of session_register and now everything works.
Post Reply