Results 1 to 34 of 34

Thread: [RESOLVED] Verifying before accessing form?

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    166

    Resolved [RESOLVED] Verifying before accessing form?

    I'm trying to use a verification before a user can access a form to help limit the amount of spam. I'm really lost on this one.

    From what I've read in some of the other posts this method doesn't sound very effective but it's what I'm working with.

    The code I have below generates the image that the user types to verify. I'm not sure why it's not first in the code but the description says to put it after the last else statement in the code.


    PHP Code:
    }else{

    echo "</select><br />";
    $new_string;

    $im = ImageCreate(144, 30);

    $white = ImageColorAllocate($im, 255, 255, 255);
    $black = ImageColorAllocate($im, 0, 0, 0);
    srand((double)microtime()*1000000);

    $string = md5(rand(0,9999));
    $new_string = substr($string, 17, 5);

    ImageFill($im, 0, 0, $black);

    ImageString($im, 5, 50, 5, $new_string, $white);

    ImagePNG($im, "verify.png");
    echo   " <img src=\"verify.png\" ><br />";
    ImageDestroy($im);
    echo "Please type the numbers from the image into the input box below <br />";
    echo   "<input type=\"hidden\" type=\"text\" name=\"new_string\" value=\"$random\">";
    echo   "<input name=\"random\" type=\"text\" value=\"\" ><font size=\"2\"><br />";


    ?>
      <input type="submit" name="select" value="Select">
      <input type="submit" name="insert" value="New Record">
      <input type="submit" name="delete" value="Delete Record">
     </form>

    <?
    }
    ?>
    The $random variable holds the text which the end user typed which should match what was in the image generated. If they don't type anything and try to proceed they are reminded to type the image in the text box. If it's wrong then they keep rentering until correct. The characters in the image are regenerated with a different string on each try.

    I'm not sure how this part of the code is suppose to work. The way it is now they are asked to retype the code before they have even entered it for the first time.



    PHP Code:
    <?PHP
    include "connect.php";

    $random trim($_POST[random]);
       if (
    $_POST[new_string]!=$random){
       echo 
    "You must type the code from the black box";
       } else {
       if (
    $_POST[new_string]->is_valid) { 
       echo 
    "You got it!";
       } else {    
        echo 
    "Please re-type the numbers from the image into the input box. <br />";
        echo 
    ImagePNG($im"verify.png");    
       } 
       } 

    if(
    $_POST['insert']){

      
    //Create a form to enter new record to add to database.
      
    echo "<form name =\"new\" action\"form5.php\" method=\"post\">
         Insert data into boxes below:<br />
         ISBN:<input type=\"text\" name=\"isbn\"><br />
         Author:<input type=\"text\" name=\"author\"><br />
         Title:<input type=\"text\" name=\"title\"><br />
         Price:<input type=\"text\" name=\"price\"><br />
         <input type=\"submit\" name=\"new\" value=\"Enter\">
         </form>"
    ;
    Last edited by Blue1974; May 6th, 2010 at 05:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width