Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Installing Captcha. Small problem but can't seem to figure it out

    I'm installing captcha on a contact form, and I've run into a small problem.

    This is the coding I'm having trouble with:
    PHP Code:
    <?php
       session_start
    ();
       if((
    $_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
     
          
    // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
          
    unset($_SESSION['security_code']);
       } else {
     
          
    // Insert your code for showing an error message here
       
    }
    ?>
    Directions from the site on installing this code:
    Place the following in the code where the form is submitted to. This code
    will check what the user has typed matches the code in the image.


    The page where the captcha is installed is letterphotography.net/contact.php
    The confirmation page or email successful page is letterphotography.net/sendemail.php

    I've been having problems installing the code and just don't know where to go from here. I'd appreciate the extra help. Thanks everyone

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    That snippet would go into the sendmail.php script.
    But do you have some other validation in sendmail.php that will
    send the user back if they enter something wrong?

    It will be important to retain the text in the texboxes when you
    send them back to re-enter a captcha code. So, we have to know
    what you are already doing about "invalid" data.


    .

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Thats just to check the captcha code entered is correct. The code you need to use to generate the actual captcha is a class from white hat web design (since removed from their website since their recent overhaul).

    You need the actual class to generate the captcha image and set the session. White hat revamped their site recently and I've not seen it there again since so I've included a link to the article on the way back machine:
    http://web.archive.org/web/200905011...hp-captcha.php

    PS In future its useful to tell us what the problem actually is rather than leave us to guess

    Edit:
    Just found they've reinstated the article:
    http://www.white-hat-web-design.co.u...curity-images/
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    TangoForce, the captcha is installed. That's not the problem. However, the site that I was taking installation details from asks me to install the code I listed on the page where the form is submitted too.

    I can't figure out where this snipped of code belongs.

    Mlseim, I figured it belonged on the sendemail.php page, but where? I'm not too PHP savvy so I can't see where this code would fit in.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    It fits in around your code that you want to run if the captcha is correct. Did you not see the comments in the code?

    In the area that has the comment:
    // Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
    THAT is where you put your normal code.

    In the area that says
    // Insert your code for showing an error message here
    That is where you put your error code.

    What is difficult about that? - You could use an include() in both areas instead if you prefer - eg include("sendmail.php");

    What exactly is the problem you're having with inserting your code? Do you actually have any code to put there or is that what you want help with?

    Of course if you show us the source from sendmail.php....
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tangoforce: Whoops! I did not realize you could not see the php code on sendemail.php. The reason I'm having difficulty is I'm not PHP savvy one bit, and when I tried doing it myself I got several error messages.

    The code on the sendemail.php is this
    PHP Code:
    <?php
    $ip 
    $_POST['ip']; 
    $httpref $_POST['httpref']; 
    $httpagent $_POST['httpagent']; 
    $visitor $_POST['visitor']; 
    $visitormail $_POST['visitormail']; 
    $notes $_POST['notes'];
    $attn $_POST['attn'];


    if (
    eregi('http:'$notes)) {
    die (
    "Do not try that! ! ");
    }
    if(!
    $visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
    {
    echo 
    "<h2>Use Back - please enter valid e-mail</h2>\n"
    $badinput "<h2>Feedback was not submitted</h2>\n";
    echo 
    $badinput;
    die (
    "Go back! ! ");
    }

    if(empty(
    $visitor) || empty($visitormail) || empty($notes )) {
    echo 
    "<h2>Use Back - please fill in all fields</h2>\n";
    die (
    "Use back! ! "); 
    }

    $todayis date("l, F j, Y, g:i a") ;

    $attn $attn 
    $subject 'Letter Photography Customer Service Request'

    $notes stripcslashes($notes); 

    $message " $todayis [EST] \n
    Attention: $attn \n
    Senders Name: $visitor \n
    Message: $notes \n 
    From: $visitor ($visitormail)\n
    Referral : $httpref \n
    "
    ;

    $from "From: $visitormail\r\n";


    mail ('sales@letterphotography.net'$subject$message$from);

    ?>
    Now how should it look with the other code tied in?

    Thanks for your help

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    PHP Code:
    <?php
       session_start
    ();
       if((
    $_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
     
          
    // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
    $ip $_POST['ip']; 
    $httpref $_POST['httpref']; 
    $httpagent $_POST['httpagent']; 
    $visitor $_POST['visitor']; 
    $visitormail $_POST['visitormail']; 
    $notes $_POST['notes'];
    $attn $_POST['attn'];


    if (
    eregi('http:'$notes)) {
    die (
    "Do not try that! ! ");
    }
    if(!
    $visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
    {
    echo 
    "<h2>Use Back - please enter valid e-mail</h2>\n"
    $badinput "<h2>Feedback was not submitted</h2>\n";
    echo 
    $badinput;
    die (
    "Go back! ! ");
    }

    if(empty(
    $visitor) || empty($visitormail) || empty($notes )) {
    echo 
    "<h2>Use Back - please fill in all fields</h2>\n";
    die (
    "Use back! ! "); 
    }

    $todayis date("l, F j, Y, g:i a") ;

    $attn $attn 
    $subject 'Letter Photography Customer Service Request'

    $notes stripcslashes($notes); 

    $message " $todayis [EST] \n
    Attention: $attn \n
    Senders Name: $visitor \n
    Message: $notes \n 
    From: $visitor ($visitormail)\n
    Referral : $httpref \n
    "
    ;

    $from "From: $visitormail\r\n";


    mail ('sales@letterphotography.net'$subject$message$from); 
          unset(
    $_SESSION['security_code']);
       } else {
     
          
    // Insert your code for showing an error message here
       
    }
    ?>
    Something like that
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by crashgrad47 View Post
    and when I tried doing it myself I got several error messages.
    Always useful to show those but try the code above and let us know of any issues.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks tangoforce, you've been a great help so far.

    I copy and pasted the code you supplied. After I complete the contact form on contact.php, whether I get the captcha right or wrong, i get this message on the sendemail.php page:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home2/letterph/public_html/sendemail.php:12) in /home2/letterph/public_html/sendemail.php on line 93
    Please note, I did not add code at either spots that requested it because I'm totally clueless as to what to add there.

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    So its saying there is a problem on line 93.. I asked you to show the source from sendmail.php.. you posted what.. 20 - 30 lines?

    Post the entire thing please. We can't solve errors on line 93 unless you show us what we're up against.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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