Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6476113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:47:08+00:00 2026-05-25T06:47:08+00:00

I have a captcha script and it works good. But, I don’t know how

  • 0

I have a captcha script and it works good. But, I don’t know how to make it refresh.

Here’s verificationimage.php:

<?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 < 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);
?>

And, the page with the form:

<label for="verif_box" style="margin-top:10px;">Image Verification:</label>

<input name="verif_box" type="text" id="verif_box" autocomplete="off" minlength="4" maxlength="5" class="text" />

<img id="captcha" src="verificationimage.php?<?php echo rand(0,9999);?>" 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;" /> &nbsp; (<a href="#captcha" class="fancybox">what's this?</a>)
<br />
<br />

    <?php 
    //if the variable "wrong_code" is sent from previous page then display the error field
    if(isset($_GET['wrong_code'])){?>
    <div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">The code you entered does not match the image. Please try typing what you see in the image to the right again.</div><br /> 
    <?php ;} ?>

Here is what happens in mailer.php:

// 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&subject=$subject&email=".urlencode($email)."&message=".urlencode($message)."&wrong_code=true");
    exit;
}

It all currently works great, but how can I make the captcha refresh? I tried doing this:

<script>
$(document).ready(function() {
$('#refresh').click(function() {
$('img#captcha').attr('src','verificationimage.php?<?php echo rand(0,9999);?>');
});
});
</script>
<a href="#" id="refresh">refresh</a>

But, it doesn’t work.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:47:09+00:00Added an answer on May 25, 2026 at 6:47 am

    My answer is similar to the one in the comments, likely a cached copy is being used on the refresh, but it’d be cleaner to use a proper method to make sure the browser doesn’t cache that image rather than a random string. On the image generation page, add this:

    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code like this. <html> <head> <title>Captcha With Refresh Feature</title> <script src=jquery.js
I have this code which works. $.ajax({ type: GET, url: includes/process.php, data: captcha= +
I have a captcha script on captcha link it uses following code: include 'kcaptcha/kcaptcha.php';
I have the following code validation php script: if(empty($_POST['captcha_code'])) { $error = 1; $code[3]
I have created PHP GD image for captcha, file called image.php each time it
I am having a classes which have function to make random text and captcha
I'm working with my simple PHP captcha algorithm ( http://www.source.ofitall.com/devel/captcha.php ) and I have
I am using a custom captcha php script along with news letter scripts to
I have ajax domain lookup script. Look here for DEMO: Here is JS code
Hy , I have this ajax code that works fine in Chrome but in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.