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

  • Home
  • SEARCH
  • 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 8524549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:43:07+00:00 2026-06-11T07:43:07+00:00

i’d like some help please. I’m having a contact form in which i’d like

  • 0

i’d like some help please.

I’m having a contact form in which i’d like to add some captcha, with NO GD Library. I’ve added some images as a guide but there are static right now. What i’m trying to do is to output in a loop the images that will match with the code (random number) in the hidden field, for example if the random number is “18301” will display the appropriate images for each number, here is my code so far:

<label for="captcha">Type the code you see (*):<br />
    <?php (do a loop here){ ?>
<img src="images/0<?php echo $num; ?>.gif" width="18" height="30" />
<?php } ?>  

     <img src="images/00.gif" width="18" height="30" />
         <img src="images/01.gif" width="18" height="30" />
         <img src="images/08.gif" width="18" height="30" />
         <img src="images/03.gif" width="18" height="30" />
         <img src="images/00.gif" width="18" height="30" />
         <img src="images/01.gif" width="19" height="30" /> =</label>
    <span id="spryCaptcha">
    <input type="text" name="captcha" id="captcha" tabindex="70" />
    <input name="hiddenCode" type="hidden" value="<?php echo rand(000000,999999); ?>"/>

How can i make this works so that the correct images will appear each time and checkes the user’s input will match to the code he/she sees each time??

  • 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-06-11T07:43:09+00:00Added an answer on June 11, 2026 at 7:43 am

    you should initialize the random number before the loop:

    <?php
        $random = (string)rand(0,999999);
    ?>
    <label for="captcha">Type the code you see (*):<br />
        <?php for($i=0; $i<strlen($random); $i++){ ?>
            <img src="images/0<?php echo $random{$i}; ?>.gif" width="18" height="30" />
        <?php } ?>  
    </label>
    <span id="spryCaptcha">
    <input type="text" name="captcha" id="captcha" tabindex="70" />
    <input name="hiddenCode" type="hidden" value="<?php echo $random ?>"/>
    

    but your should save that in a session and check afterwards (because an hidden field is 0 security):

    call session_start() on top of your page

    <?php
        $random = (string)rand(0,999999);
        $_SESSION['captcha'] = $random;
    ?>
    <label for="captcha">Type the code you see (*):<br />
        <?php for($i=0; $i<strlen($random); $i++){ ?>
            <img src="images/0<?php echo $random{$i}; ?>.gif" width="18" height="30" />
        <?php } ?>  
    </label>
    <span id="spryCaptcha">
    <input type="text" name="captcha" id="captcha" tabindex="70" />
    

    and check on next page for your $_POST['captcha'] against $_SESSION['captcha']

    still, this is 0 security as image names can be read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

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.