Page 1 of 1

Simple session help

Posted: Wed Feb 24, 2010 4:48 pm
by Awesomeness
I'm having trouble getting rid of a variable in my session:

Code: Select all

<?php
 
session_start(); //Use the session we made to get the client's input
 
$user_content=trim($_POST['user_content']);
$captcha_guess=strtolower(trim($_POST['captcha_guess']));
 
if(isset($_SESSION['encoded_captcha'])) {
    if($_SESSION['encoded_captcha'] == md5($captcha_guess)) {
        if($user_content != "") {
            //It's a human, or a really smart bot
            echo("<p style='color:green;'>Congratz!  You passed the CAPTCHA test!  Your submition has been received.  It was: ");
            echo($user_content);
        } else {
            echo("<p style='color:red;'>Your submission is empty.  Try again.</p>");
        }
    } else {
        //The bot (either that or he's an idiot) entered the wrong captcha
        //Pwn him!!!
        echo("<p style='color:red;'>You did not enter the CAPTCHA correctly.  Try again.</p>");
    }
}
unset($_SESSION]["encoded_captcha"]);
 
?>
What am I doing wrong? I've looked through the documentation of unset(), but it didn't help me.

Re: Simple session help

Posted: Wed Feb 24, 2010 5:16 pm
by klevis miho
Do a session_destroy();

Re: Simple session help

Posted: Wed Feb 24, 2010 5:24 pm
by Awesomeness
klevis miho wrote:Do a session_destroy();
I have 2 problems with that:

a: I've already tried it, it didn't work.
b: When I continue building my website, I might need my session later.

When I first go to the page with this code, before my session variable is created, it does what I want, so I know that the problem is with unset().

Re: Simple session help

Posted: Wed Feb 24, 2010 5:27 pm
by klevis miho
You have a error in the syntax:
make this:
unset($_SESSION]["encoded_captcha"]);

to this:
unset($_SESSION["encoded_captcha"]);

Re: Simple session help

Posted: Wed Feb 24, 2010 7:50 pm
by Awesomeness
Even when there is no syntax error, it still doesn't work.

Re: Simple session help

Posted: Wed Feb 24, 2010 8:07 pm
by Awesomeness
Nevermind, with thorough research I discovered that it is a PHP bug. I've implemented a complicated alternative that seems to work.