Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make my CAPTCHA script have a refresh link?
    primarykey
    data
    text
    <p>I have a captcha script and it works good. But, I don't know how to make it refresh. </p> <p>Here's <code>verificationimage.php</code>: </p> <pre><code>&lt;?php header('Content-type: image/jpeg'); $width = 50; $height = 24; $my_image = imagecreatetruecolor($width, $height); imagefill($my_image, 0, 0, 0xFFFFFF); // add noise for ($c = 0; $c &lt; 40; $c++){ $x = rand(0,$width-1); $y = rand(0,$height-1); imagesetpixel($my_image, $x, $y, 0x000000); } $x = rand(1,10); $y = rand(1,10); $rand_string = rand(1000,9999); imagestring($my_image, 5, $x, $y, $rand_string, 0x000000); setcookie('tntcon',(md5($rand_string).'a4xn')); imagejpeg($my_image); imagedestroy($my_image); ?&gt; </code></pre> <p>And, the page with the form:</p> <pre><code>&lt;label for="verif_box" style="margin-top:10px;"&gt;Image Verification:&lt;/label&gt; &lt;input name="verif_box" type="text" id="verif_box" autocomplete="off" minlength="4" maxlength="5" class="text" /&gt; &lt;img id="captcha" src="verificationimage.php?&lt;?php echo rand(0,9999);?&gt;" alt="This form can't be submitted because images aren't displayed" title="Verification image, type it in the box" width="50" height="24" align="absbottom" onclick="$('#verif_box').focus();" style="cursor:pointer;" /&gt; &amp;nbsp; (&lt;a href="#captcha" class="fancybox"&gt;what's this?&lt;/a&gt;) &lt;br /&gt; &lt;br /&gt; &lt;?php //if the variable "wrong_code" is sent from previous page then display the error field if(isset($_GET['wrong_code'])){?&gt; &lt;div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;"&gt;The code you entered does not match the image. Please try typing what you see in the image to the right again.&lt;/div&gt;&lt;br /&gt; &lt;?php ;} ?&gt; </code></pre> <p>Here is what happens in <code>mailer.php</code>: </p> <pre><code>// check to see if verificaton code was correct if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){ // if verification code was correct send the message and show this page mail("email@domain.com", 'New WeeBuild Support Ticket: '.$subject, $emailContent, $headers); mail($email, 'Thank you for contacting WeeBuild Support! (#'.$ticket.')', $emailContents, $headers2); // add to database $today = getdate(); $theDate = $today["weekday"].", ".$today["month"]." ".$today["mday"].", ".$today["year"]; mysql_select_db("database_name", $con); $sql="INSERT INTO table_name (name, email, subject, message, ticket, ip_address, created) VALUES ('$_POST[name]','$_POST[email]','$_POST[subject]','$_POST[message]','$ticket','$_SERVER[REMOTE_ADDR]','$theDate')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } //close the database connection mysql_close($con); // delete the cookie so it cannot sent again by refreshing this page setcookie('tntcon',''); } else if(isset($message) and $message!=""){ // if verification code was incorrect then return to contact page and show error header("Location: index.php?name=$name&amp;subject=$subject&amp;email=".urlencode($email)."&amp;message=".urlencode($message)."&amp;wrong_code=true"); exit; } </code></pre> <p>It all currently works great, but how can I make the captcha refresh? I tried doing this:</p> <pre><code>&lt;script&gt; $(document).ready(function() { $('#refresh').click(function() { $('img#captcha').attr('src','verificationimage.php?&lt;?php echo rand(0,9999);?&gt;'); }); }); &lt;/script&gt; &lt;a href="#" id="refresh"&gt;refresh&lt;/a&gt; </code></pre> <p>But, it doesn't work. </p> <p>By the way, I don't want to use reCaptcha, I just rather do it this way because reCaptcha, to me, looks hard to set up with my stuff. </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.
 

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