I've just spent many hours tearing my hair out trying to work out why my PHP code wasn't working with sessions. Having found the answer I want to share it with everybody - so that I can save you many hours of anguish!
The problem was as follows:
I had a simple PHP page like this:
<?php
session_start();
$_SESSION['sess_var'] = "Hello World";
echo("The contents is '" . $_SESSION['sess_var']);
echo ("SID is " . session_id() . " \n");
?>
Yet when I refreshed it in the web browser, I would get a different value for the SID every time - in other words, the PHP session was not working.
I am running Zone Alarm Pro version 5.0 . When cookie or ad blocking control is enabled (Privacy | Main tab) the sessions in PHP won't work. When they are disabled, PHP sessions will work. Note that this problem is confined to the server on my local machine (i.e. session cookies work for outside web pages, just not those hosted by my local server).
If you view the source of a page server from a machine with Zone Alarm running, with cookie or ad blocking enabled, you will see:
<script language='javascript' src='http://127.0.0.1:1026/js.cgi?caw&r=27531'></script>
or similar present. When this is the case, PHP session won't work (at least they don't for me) when you connect to a server running on your box. Once cookie and ad blocking are disabled, the extra line in the HTML goes away and PHP sessions magically work again!
I hope that this solves someone else's problems.
<?php