Take the 2-minute tour ×
//Check against CSFR here
            $key = md5(uniqid(rand(), TRUE));
            //$key = "234"; //using this works but not the idea
            $_SESSION['key'] = $key;

<form method="post" action="<?php echo HTTPF; ?>/complete_reg">
                <b>Email address:</b><br />
                <input type="text" id="user_email" name="user_email" value="" class="register_email" onblur='$("#checkid").html("Please wait..."); $.get("er_checkuser.php",{ cmd: "check", check_key: $("#check_key").val(), user: $("#user_email").val() } ,function(data){  $("#checkid").html(data); });' />
            <input type="hidden" id="check_key" name="check_key" value="<?php echo $key; ?>" />
            <span style="color:red; font: bold 12px verdana; " id="checkid" ></span>


//calling page
    $get[$key] = filter($value);

//For some reasons I don't know why the values are not the same but they should be
if ($get['check_key'] == $_SESSION['key'])


    echo $_SESSION['key'];
    echo "<br>";
    echo $get['check_key'];
share|improve this question
i can't see session_start() anywhere... –  Sascha Galley Jul 15 '11 at 22:14
There is session_start() at the beginning of the pages (not shown) –  Frank Nwoko Jul 16 '11 at 10:59

3 Answers 3

Ah I think I know where the problem is: you create a new key on every page reload. So you also create a new key when submitting the form.

What you should do is:

if(!isset($_GET['check_key']) {
    $_SESSION['key'] = $key;
share|improve this answer
When I do this, $get['check_key'] doesn't have a value at the calling page. –  Frank Nwoko Jul 16 '11 at 11:01

Do you call session_start() before using the $_SESSION array?

share|improve this answer
Make sure you call session_start(); on each page that is going to use the $_SESSION variable. –  Brian Graham Jul 15 '11 at 22:17

You should call session_start() at the top of your php script or else I won't work.


Maybe you can watch this video from nettuts to learn how to create login system, which uses sessions.

share|improve this answer

Your Answer


