Web Analytics Made Easy -
StatCounter Installing Captcha. Small problem but can't seem to figure it out - CodingForum

Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.


    .

    Comment


    • #3
      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:


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

      "Tango says double quotes with a single ( ' ) quote in the middle"
      '$Name says single quotes with a double ( " ) quote in the middle'
      "Tango says double quotes ( \" ) must escape a double quote"
      '$Name single quotes ( \' ) must escape a single quote'

      Comment


      • #4
        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.

        Comment


        • #5
          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....
          "Tango says double quotes with a single ( ' ) quote in the middle"
          '$Name says single quotes with a double ( " ) quote in the middle'
          "Tango says double quotes ( \" ) must escape a double quote"
          '$Name single quotes ( \' ) must escape a single quote'

          Comment


          • #6
            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 ('[email protected]'$subject$message$from);

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

            Thanks for your help

            Comment


            • #7
              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 ('[email protected]'$subject$message$from); 
                    unset(
              $_SESSION['security_code']);
                 } else {
               
                    
              // Insert your code for showing an error message here
                 
              }
              ?>
              Something like that
              "Tango says double quotes with a single ( ' ) quote in the middle"
              '$Name says single quotes with a double ( " ) quote in the middle'
              "Tango says double quotes ( \" ) must escape a double quote"
              '$Name single quotes ( \' ) must escape a single quote'

              Comment


              • #8
                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.
                "Tango says double quotes with a single ( ' ) quote in the middle"
                '$Name says single quotes with a double ( " ) quote in the middle'
                "Tango says double quotes ( \" ) must escape a double quote"
                '$Name single quotes ( \' ) must escape a single quote'

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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.
                    "Tango says double quotes with a single ( ' ) quote in the middle"
                    '$Name says single quotes with a double ( " ) quote in the middle'
                    "Tango says double quotes ( \" ) must escape a double quote"
                    '$Name single quotes ( \' ) must escape a single quote'

                    Comment

                    Working...
                    X
                    😀
                    🥰
                    🤢
                    😎
                    😡
                    👍
                    👎