IIS7 PHP $_SESSION issue

Background: so before i get to the “can you help the noob” part. here’s the background. im running an amazonaws server running a Business Server 2008 Datacenter image. on there, i’ve got IIS7 installed.

The Setup: ok. so here’s the dealio. i’ve got a fake e-commerce thing running as a project for class. one of the features obv enough is the cart. im using $_SESSIONS to move info around the site for tracking what users are putting into their carts.

The Problem: the issue is that it works perfectly in my Apache server, but not on the IIS server, i’ve narrowed down the 500 error i get to whenever the site tries to use a $_SESSION variable. which leads me to believe it’s a configuration or permissions issue.

The Example: When you add something to the cart, it works fine. the session is set, and everything gets transferred properly, however, further access to this variable (such as trying to manipulate it by removing items from the cart, viewing the items in the cart after adding one item, etc) results in an 500 error. see attachment

The code: just to give you guys an idea of what i’ve got. i built a Cart class to handle adding, removing, and viewing of all products i put in the cart. i’ve included only the functions that are being used when the error occurs.

[php]<?php
session_start();

class Cart
{
public function __construct()
{
//ensure cart is set
if(isset($_SESSION[‘cart’]))
{
if(empty($_SESSION[‘cart’]))
{
$_SESSION[‘cart’] = array();
}//end if
}//end if
else
{
$_SESSION[‘cart’];
}//end else

    //ensure cartItems are set
    if(isset($_SESSION['numItems']))
    {
        if($_SESSION['numItems'] < 1)
        {
            $_SESSION['numItems'] = 0;
        }//end if
    }//end if
    else
    {
        $_SESSION['numItems'];    
    }//end else
}//end construct

public function addItem($item)
{
    $_SESSION['cart'][] = $item;
    $_SESSION['numItems']++;
}//end addItem

public function removeItem($item)
{
    unset($_SESSION['cart'][$_POST['rem-ID']]);
    $_SESSION['cart'] = array_values($_SESSION['cart']);
    $_SESSION['numItems']--;
}//end removeIem

}//end class

?>[/php]

The Details: So just to clarify some things to make sure you’re up to date on what i’ve done to try to resolve this issue. here’s a list of things i’ve ensured, checked, and tried:
could I have dun goofed? - No, i have checked my code 100% with a magnifying glass, a fine-tooth comb, and enough caffeine to make a sloth hyper. i know that code so well now that i could find waldo in it. i am positive that the code is perfect.

have you checked php? - i have, my php settings are exactly the same on both my apache and IIS. and no. i haven’t forgotten to include session_start(); on any of the required pages. as stated, the code is perfect.

what about the NTFS permissions? - here’s where you got me. yes, i have checked the web.config file, however im unsure as to what im looking for/ what to change if i find it when it comes to NTFS permissions and even what they’re used for. im actually posting this because google chose to betray my trust in it. i have found nothing regarding it.

   I've also checked the log files for IIS as well as windows and other logs within the server to try to find the crash written. i haven't found anything as of yet.

That’s about all i can think of at the moment, if you need further clarification feel free to ask. i’m including a screenshot of the error i get when the application crashes. any help whatsoever would be greatly appreciated.

Check your php.ini and make sure you have error_reporting = E_ALL and display_errors = On

I’m not sure about on IIS but I know with Apache if you have display_errors = Off and log_errors = On it will issue a 500 error.

Sponsor our Newsletter | Privacy Policy | Terms of Service