www.webdeveloper.com
Results 1 to 15 of 15

Thread: how to add captcha to a php form

  1. #1
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459

    how to add captcha to a php form

    anyone know where i can get the script to use captcha on a form? Like on
    http://www.websitehaven.com/webdesign.php

  2. #2
    Join Date
    Jun 2008
    Posts
    277

  3. #3
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    as you can see i have a captcha but it doesnt work

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,290
    It will depend on if your web host has the right Library enabled.

    On a tech note though, php4 is like windows 98, its had its day, currently php5 is a stable release and the buzz word is PHP6 is under development.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Jun 2008
    Posts
    277
    HTML Code:
    as you can see i have a captcha but it doesnt work
    Sorry, didn't see a captcha on the page, presumed you were looking for one. my fault.

  6. #6
    Join Date
    Jul 2008
    Posts
    13
    These are Captcha services, but I like them:

    recaptcha.net

    or

    captchas.net

  7. #7
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    i dont want a program, I dont want a 3rd p[arty site, there has to be a way to intergrate it into my site, I have it enabled but it doesnt seem to work the way I want it too

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,221
    What have you enabled? There's no way for us to know why it does not work if we don't know what PHP code you are using to try to make it work.

    PS: What is your alternative for visually impaired users? At least using a third-party solution like www.recaptcha.net your users would have an audio option. Personally, I've decided to eschew annoying captchas entirely and gone with a couple anti-robot techniques to make life a bit more difficult for them: www.charles-reace.com/PHP_and_MySQL/Contact_Form .
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    visually impaired? I mean how can you be visually impaired and go online? I mean there is no option, I think I might have ti do something like 123456 in a form, or type yes if they are a human something klike that

  10. #10
    Join Date
    Jul 2008
    Posts
    13
    I wish that Captchas weren't necessary! The JustHumans tool is an interesting alternative, too. You click a picture instead of having to enter several letters.

    justhumans.com

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,221
    Most common solution for the visually impaired is text to speech readers. And even someone like myself who has a damaged retina but can still read text pretty well may have trouble with that obscured captcha image on your site and just get frustrated and decide to go somewhere else.

    PS: Depending on where in the world you are and what sort of service you are providing, you might even be susceptible to legal action if your site is not handicapped accessible.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    are you serious? I mean I have been running babyjai.com without a captcha for a long time, but I never knew that about being sued, they can sue the company not me, but I didnt know that. How would i just make a form where they have to put in like a set amount of number or a word?

  13. #13
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,221
    [foreshadowing]I actually address some of your technical question at the end of this post.[/foreshadowing]

    I'm not saying you would be sued, or that your site necessarily comes under any such jurisdiction, as I'm certainly not a lawyer and have no desire to be. I just wanted to bring to your attention that a graphic-only captcha can be an accessibility issue. Whether or not you have a legal, moral, or commercial reason to worry about that is really your concern.

    In the US, if your site is for any Federal agency, then it must comply to Section 508 for accessibility. I do not know if there are any other federal regulations at this time that apply to non-federal websites, and of course different states may have their own regulations.

    It is my understanding that in the UK the Disability Discrimination Act is more wide-ranging in its applicability than Section 508 is here. But again, I am not lawyer, so consider all this to be "food for thought" at this point.

    If you are interested in site accessibility, there is a forum right here at webdeveloper.com with a number of information "sticky" posts that might be worth a look.

    Anyway...if you want to employ some sort of captcha, whether it be graphic or text or audio or whatever, the general process would be to generate the string, save it in a session variable, then provide the necessary prompt to the user for what needs to be entered. Then when you validate the form input, you check the value entered against that stored in the session variable. (Remember that both the form page and the form processor page will need to have a session_start() before any output is generated and before any data is read from or written to the $_SESSION array.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  14. #14
    Join Date
    Jun 2003
    Location
    Jerzy
    Posts
    459
    thanks for that info, I dont really know to much about php, but I can post the php mailer here, its a general mailer, but I need to know how to add the string so it can be entered, this way its regular text and dont have to worry about a captcha image only thing

  15. #15
    Join Date
    Jan 2013
    Posts
    5
    TO Create a simple Captcha form, then here is a small guide:

    ===== 1 STEP ======
    in your FTP folder (where you need), put a font file (for example, this: http://www.webpagepublicity.com/free...Anklepants.ttf )
    then create a file (called captcha.php) and paste the below code inside it (then put that captcha.php in the same ftp folder):


    Code:
    <?php
    session_start();
    
    // generate random number and store in session
    $randomnr = rand(1000, 9999);
    $_SESSION['randomnr2'] = md5($randomnr);
    //generate image
    $im = imagecreatetruecolor(100, 38);
    //colors:
    $white = imagecolorallocate($im, 255, 255, 255);
    $grey = imagecolorallocate($im, 128, 128, 128);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 200, 35, $black);
    
    // -------------      your fontname    -------------
    $font = 'Anklepants.ttf';
    
    //draw text:
    imagettftext($im, 35, 0, 22, 24, $grey, $font, $randomnr);
    
    imagettftext($im, 35, 0, 15, 26, $white, $font, $randomnr);
    
    // prevent client side  caching
    header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revаlidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    
    //send image to browser
    header ("Content-type: image/gif");
    imagegif($im);
    imagedestroy($im);
    ?>



    ===== 2 STEP ======

    then in any page (where you want to implement the captcha) put this code somewhere inside that page (but of course, in the last part of this code, there is a sample php fucntion to make an sample action if code is entered correctly. So you should know a more php programming to execute your desired fucntions when Captcha is correct):

    Code:
    <form method="post" action=""> <img src="captcha.php" />
     <input class="input" type="text" name="codee" />
     <input type="submit" value="Submit" />
    </form>
    
    <?php
    session_start();
    if (md5($_POST['codee']) == $_SESSION['randomnr2']) { 
     // here you  place code to be executed if the captcha test passes
      echo "YES. Do Something function1";
    } 
    
    else {  
     // here you  place code to be executed if the captcha test fails
      echo "No.  Do Something function2";
    }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles