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

    Hi Gazzamop

    I've had problems with Zone Alarm. I once spent an entire evening uninstalling and re-installing MySQL on Windows because I thought it wasn't working. It was working, but Zone Alarm was silently blocking the client access to the server. No access requests - nothing. When I updated to Zone Alarm 4.5, that problem went away.

    I now have a problem with Zone Alarm because I can't surf with it active at all. I just switched to DSL and now have a router with a hardware firewall. I can only surf if Zone Alarm is off. I have now installed XP SP2 and activated the Windows firewall. I'm not happy with this solution, but it's better than nothing. I've looked for settings in Zone Alarm that will stop blocking my internet access, but I can't find anything. The ethernet card is correctly recognized in the secure zone, but it still doesn't work.

    I (was) using Zone Alarm freeware with the latest updates.

    Norm

      Write a Reply...