I have this simple php code that generate a random code and display it to the user. I need to verify using a text input if the user insert the displayed code, like a captcha, but i will use this script to redirect the user after the verification,to the registration form page. The code is generated, but i can't verify it, maybe i've missed something in the code?
NB: This is not a spam prevention system. As said in the comments, there are valid solution better than this to prevent spam. This is a starting draft for an user invitation system, if you want to downvote the question please consider this.
<?php 
function randomCode() {
    $code_variable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
    srand((double)microtime() * 1000000);
    $i = 0;
    $rand_Code = '';
    while ($i <= 7)
        {
        $num = rand() % 33;
        $tmp = substr($code_variable, $num, 1);
        $rand_Code = $rand_Code . $tmp;
        $i++;
        }
    return $rand_Code;
}
$code = randomCode(); 
if(isset ($_POST['verify'])){
    if($_POST['user_code'] == $code ){
        echo 'Valid code.';
        header('Location: index.php');
    }
}
?>
<form method="post" action="">
<input type="text" name="verification_code" disabled value="<? echo $code;?>">
<input type="text" name="user_code">
<button type="submit" name="verify">Verify code</button>
</form>
 
    