This may or may not be related, but IF your PHP scripts are being hosted on a Windows system running IIS, then the issue could be related to a bug which exists in many releases of the PHP engine for Windows. For details, see the original posting at
http://www.php.net/bugs.php?id=5493
and the subsequent posting, after the bug reappeared, at
http://www.php.net/bugs.php?id=8989
This bug was resolved in the Windows CGI version in v4.0.2, but reappeared in 4.0.4. The last release that worked properly with sessions was 4.0.3pl1 (which I currently use for this very reason).
The problem you describe sounds very similar to what I've posted. If you can, read PHP bug #8989, create the four scripts listed, and see if you get the same result. If so, PLEASE post to that problem, as I am having a heck of a time getting anyone to resolve this issue, and if they saw more people posting, they might take it more seriously.
The only way to know what kind of system is hosting your site, if you don't already know for sure, is to create a simple script. I always have a simple file called VERSION.PHP in which I have quite simply
<?php
phpinfo();
?>
This should tell you everything you need to know about what kind of host your site runs on, what version of PHP they have, etc.
Please note if this is NOT a Windows system, I can't honestly speak about the problem.
Regarding your code, at the very top, it is wise to FIRST execute session_start(), as session_unset() does not cause a session to initiate, at least as explained in the PHP manual, 4th paragraph from the top, here:
http://www.php.net/manual/en/ref.session.php
Also note, according to the same manual, session_unset() doesn't take any parameters. It frees all session variables. Details here:
http://www.php.net/manual/en/function.session-unset.php
Another question: How is your webhosting site configured PHP-wise? That is, do they have the following items correctly configured:
- Do they have session.save_path properly set to a location where session files can be saved?
- Are you counting on sessions via cookies, in which case, is the host configured with session.use_cookies = 1?
- If you're going with passing the session ID (SID) via URLs, is the host configured with session.use_trans_sid = 1, and was the engine compiled with the flag --enable-trans-sid?
All of this can be determined by creating a PHP file like the example above, and looking at what the engine tells you.
That's the best I can offer if you're on a non-Windows system I'm afraid.