PHP会话问题

I have a part of my site when any user (not just logged-in) can rate something on a form from 1 - 5. The form and the backend for it works perfectly.

I made it so that when the form POSTs, it trips $_SESSION['rated']; to equal one. Then I have an immediate redirect to the origin page. On the origin page, where the original rating form is, if $_SESSION['rated']; = 1, then the form is invisible, but if it's 0 (by default) then the form is shown.

It worked the very first time, but since then I've not been able to stop the session or unset the variables in any way. I've even tried a different browser, clearing all cookies, doing this:

session_start();
session_unset();
session_destroy();

But nothing actually clears the session, and my form still shows invisible because $_SESSION['rated']; still equals 1.

What should I do?

you wrote if $_SESSION['rated']; = 1

check your code, if you really use = (the assignment operator). if you do, that's the culprit – to compare values in php (and other c-like languages) use == (comparison operator)

Different options:

unset($_SESSION['rated']);  //Removes the 'rated' variable form $_SESSION

unset($_SESSION);           //Destroys everything inside $_SESSION

$_SESSION['rated'] = 0;     //This might be the best alternative for you

The session's just a file. Find where your PHP install's keeping the session file and look at its contents between requests. The contents are just the serialized version of $_SESSION, and is fairly easy to read. If your 'rated=1' are still in there after you did session_destroy/unset/etc..., then something else is restoring your session prior to its being serialized and saved.

try :

session_destroy();
$_SESSION = array();