Note that there are some explanatory texts on larger screens.

plurals
  1. POphp captcha code not working
    primarykey
    data
    text
    <p>I'm using an old random() function for creating a validation code for an AJAX commenting system I found on the web (source code at <a href="http://tutorialzine.com/2010/06/simple-ajax-commenting-system/" rel="nofollow" title="link">LINK</a> ).</p> <p>The idea behind is pretty simple: </p> <pre><code> function Random() { $chars = "ABCDEFGHJKLMNPQRSTUVWZYZ23456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i &lt;= 4) { $num = rand() % 32; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_code = Random(); </code></pre> <p>and then in the form, just before the SUBMIT button: </p> <pre><code>&lt;label for="security_code"&gt;Enter this captcha code: &lt;b&gt;&lt;? echo $random_code; ?&gt;&lt;/b&gt;&lt;/label&gt; &lt;input type="text" name="security_code" id="security_code" /&gt; &lt;input name="randomness" type="hidden" id="randomness" value="&lt;?php $random_code; ?&gt;"&gt; </code></pre> <p>My AJAX commenting system uses something like this for checking if a field is blank (ie. if there are any errors): </p> <pre><code>$errors = array(); $data= array(); [...] if(!($data['name'] = filter_input(INPUT_POST,'name',FILTER_CALLBACK,array('options'=&gt;'Comment::validate_text')))) { $errors['name'] = 'Please enter a name.'; } if(!empty($errors)){ [...] } </code></pre> <p>so I wrote this: </p> <pre><code>if(!($data['security_code'] = filter_input(INPUT_POST,'security_code',FILTER_CALLBACK,array('options'=&gt;'Comment::validate_text')))) { $errors['security_code'] = 'You did not enter the validation code.'; } elseif(!($data['security_code'] = $randomness)) { $errors['security_code'] = 'You entered the validation code incorrectly. Please note that it is case sensitive.'; } </code></pre> <p>However when I click on the SUBMIT button after having inserted a random text in the validation code textfield ( test it by yourself at <a href="http://www.flapane.com/guestbook/guestbook.php" rel="nofollow" title="this link">LINK</a> ) I always get the "You entered the validation code incorrectly." message.</p> <p>print_r($_POST) gives an empty array and then the script hangs after I click on submit: Array ( )</p> <p>What am I missing? The original captcha code gets lost at some point in the validation process (the 3rd and 4th blocks of code). Thanks in advance </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload