PHP - Moved: Php Form With Captcha - Amnyone Used This?
This topic has been moved to Third Party PHP Scripts.
http://www.phpfreaks.com/forums/index.php?topic=319400.0 Similar TutorialsHi, I really need to add a captcha to this PHP process form? How do I go about doing this? Code: [Select] <?php // Define some constants define( "RECIPIENT_NAME", "John Smith" ); define( "RECIPIENT_EMAIL", "john@example.com" ); define( "EMAIL_SUBJECT", "Visitor Message" ); // Read the form values $success = false; $senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : ""; $senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : ""; $message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : ""; // If all values exist, send the email if ( $senderName && $senderEmail && $message ) { $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">"; $headers = "From: " . $senderName . " <" . $senderEmail . ">"; $success = mail( $recipient, EMAIL_SUBJECT, $message, $headers ); } // Return an appropriate response to the browser if ( isset($_GET["ajax"]) ) { echo $success ? "success" : "error"; } else { ?> <html> <head> <title>Thanks!</title> </head> <body> <?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>" ?> <?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?> <p>Click your browser's Back button to return to the page.</p> </body> </html> <?php } ?> ?? Thanks in advance! Hello, I am trying to make a captcha, but having some trouble My code matches the tutorial I'm following, the 1st screenshot is the captcha.php file, the 2nd is the captcha_generate.php file, and the 3rd is the result in My browser, I am using firefox and linuxmint 10, with apache2 php5 and GD installed, any Help will be greatly appreciated!!!!! thanx GOD BLESS!!! [attachment deleted by admin] hi i was wondering if anyone had any idea how i can add code A to code b below? code a is my captcha code and code b is my contact form code thanks.. CODE A CAPTCHA: Code: [Select] <?php if(isset($_POST["captcha"])) if($_SESSION["captcha"]==$_POST["captcha"]) { echo 'CAPTHCA is valid; proceed the message'; } else { echo 'CAPTHCA is not valid; ignore submission'; } ?> CODE B CONTACT FORM: Code: [Select] <? $mailto = "me@blah.com"; $cc = ""; $bcc = ""; $subject = "Email subject"; $vname = "blah blah"; $email = $_POST['email']; function validateEmail($email) { if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email)) return true; else return false; } if(strlen($_POST['name']) < 1 || strlen($_POST['message']) < 1 || validateEmail($email) == FALSE) { $emailerror = 'Error:'; if(empty($_POST['name'])) { $emailerror .= '<li>Enter name</li>'; } if(validateEmail($email) == FALSE) { $emailerror .= '<li>Enter valid email</li>'; } if(empty($_POST['message'])) { $emailerror .= '<li>Enter message</li>'; } } else { $emailerror .= "Your email has been sent successfully"; $timestamp = date("F j, Y, g:ia"); $messageproper ="\n\n" . "Name: " . ucwords($_POST['name']) . "\n" . "Email: " . ucwords($email) . "\n" . "Comments: " . $_POST['message'] . "\n" . "\n\n" ; $messageproper = trim(stripslashes($messageproper)); mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() ); } ?> HI recently we have been starting to recieved about 30 spam emails aday. I read that the issue was how my forms were submitting and that it kept bypassing the javascript. I found some code i could use at http://chrisplaneta....with_recaptcha/ but i cannot seem to get the form to function correctly.
It is supposed to email me once the form is validated but the email does not seem to be sending.
Also i would like the form to redirect to a thank you page once it has been agreed. I did try but it kept telling me the headers had already been called. i am calling the page in with php include. Can you please advise the best way for me to relocate.
I have attached a copy of my form.php page which has every thing on. I have also included the code at the bottom of this email
Also i would appreciate any comments on what i can include on my form to limit the spammers
<?php //If the form is submitted: if(isset($_POST['submitted'])) { //load recaptcha file require_once('captcha/recaptchalib.php'); //enter your recaptcha private key $privatekey = "6Ld5Df4SAAAAAKciqwDco8dfvBR15fGeFVXWcvCO"; //check recaptcha fields $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); //Check to see if the invisible field has been filled in if(trim($_POST['checking']) !== '') { $blindError = true; } else { //Check to make sure that a contact name has been entered $authorName = (filter_var($_POST['formAuthor'], FILTER_SANITIZE_STRING)); if ($authorName == ""){ $authorError = true; $hasError = true; }else{ $formAuthor = $authorName; }; //Check to make sure sure that a valid email address is submitted $authorEmail = (filter_var($_POST['formEmail'], FILTER_SANITIZE_EMAIL)); if (!(filter_var($authorEmail, FILTER_VALIDATE_EMAIL))){ $emailError = true; $hasError = true; } else{ $formEmail = $authorEmail; }; //Check to make sure the subject of the message has been entered $msgSubject = (filter_var($_POST['formSubject'], FILTER_SANITIZE_STRING)); if ($msgSubject == ""){ $subjectError = true; $hasError = true; }else{ $formSubject = $msgSubject; }; //Check to make sure content has been entered $msgContent = (filter_var($_POST['formContent'], FILTER_SANITIZE_STRING)); if ($msgContent == ""){ $commentError = true; $hasError = true; }else{ $formContent = $msgContent; }; // if all the fields have been entered correctly and there are no recaptcha errors build an email message if (($resp->is_valid) && (!isset($hasError))) { $emailTo = 'carlycyber@hotmail.co.uk'; // here you must enter the email address you want the email sent to $subject = 'A new message from: immigration solicitors Manchester' ; $body = "Name :formAuthor \n\nEmail: $formEmail \n\nTelephone :formSubject \n\nContent: $formContent \n\n$formAuthor"; // This is the body of the email $headers = 'From: <'.$formEmail.'>' . "\r\n" . 'Reply-To: ' . $formEmail . "\r\n" . 'Return-Path: ' . $formEmail; // Email headers // Email headers //send email mail($emailTo, $subject, $body, $headers); // set a variable that confirms that an email has been sent $emailSent = true; } // if there are errors in captcha fields set an error variable if (!($resp->is_valid)){ $captchaErrorMsg = true; } } } ?> <?php // if the page the variable "email sent" is set to true show confirmation instead of the form ?> <?php if(isset($emailSent) && $emailSent == true) { ?> <?php $message = "Thank you. Your form has been submitted and a member of our team will contact you shortly.This website is developed for generating immigration enquiries in your area and it is not a law firm, your enquiries will be passed on to a solicitor.We confirm that this website does not belong to a law firm and we have no physical office in your county. Our solicitors are able to provide immigration services all over the UK because they provide a Virtual Service.Responses to your legal enquiries and the legal opinion given to you would be provided by a qualified UK Immigration Solicitor. If you decide to proceed with the solicitor, your matter will be dealt with under a Law firm regulated by the Solicitors Regulatory Authority."; echo "<script type='text/javascript'>alert('$message');</script>"; /*echo "<script language='javascript'> window.location('http://www.immigrationsolicitorsmanchesteruk.co.uk/thankyou.php') </script>";*/ ?> <p>Thank you. Your form has been submitted and a member of our team will contact you shortly.This website is developed for generating immigration enquiries in your area and it is not a law firm, your enquiries will be passed on to a solicitor.We confirm that this website does not belong to a law firm and we have no physical office in your county. </p> <?php } else { ?> <?php // if there are errors in the form show a message ?> <?php if(isset($hasError) || isset($blindError)) { ?> <p><strong>Im sorry. There was an error submitting the form. Please check all the marked fields and try again.</strong></p> <?php } ?> <?php // if there are recaptcha errors show a message ?> <?php if ($captchaErrorMsg){ ?> <p><strong>The recaptcha was not entered correctly. Please try again.</strong></p> <?php } ?> <?php // here, you set what the recaptcha module should look like // possible options: red, white, blackglass and clean // more infor on customisation can be found he http://code.google.com/intl/pl-PL/apis/recaptcha/docs/customization.html ?> <script type="text/javascript"> var RecaptchaOptions = { theme : 'blackglass' }; </script> <?php // this is where the form starts // action attribute should contain url of the page with this form // more on that you can read he http://www.w3schools.com/TAGS/att_form_action.asp ?> <form id="contactForm" action="" method="post"> <p> <strong>Full Name</strong><br/> <input class="requiredField <?php if($authorError) { echo 'formError'; } ?>" type="text" name="formAuthor" id="formAuthor" value="<?php if(isset($_POST['formAuthor'])) echo $_POST['formAuthor'];?>"size="25" /></p> <p> <strong>Email </strong><br/> <input class="requiredField <?php if($emailError) { echo 'formError'; } ?>" type="text" name="formEmail" id="formEmail" value="<?php if(isset($_POST['formEmail'])) echo $_POST['formEmail'];?>" size="25" /> </p> <p> <strong>Telephone </strong><br/> <input class="requiredField <?php if($subjectError) { echo 'formError'; } ?>" type="text" name="formSubject" id="formSubject" value="<?php if(isset($_POST['formSubject'])) echo $_POST['formSubject'];?>" size="25" /> </p> <p> <strong>Please give us some information about your enquiry</strong><br/> <textarea class="requiredField <?php if($commentError) { echo 'formError'; } ?>" id="formContent" name="formContent" cols="25" rows="5"><?php if(isset($_POST['formContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['formContent']); } else { echo $_POST['formContent']; } } ?></textarea></p> <?php // this field is visible only to robots and screenreaders // if it is filled in it means that a human hasn't submitted this form thus it will be rejected ?> <div id="screenReader"> <label for="checking"> If you want to submit this form, do not enter anything in this field </label> <input type="text" name="checking" id="checking" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" /> </div> </div> <?php // load recaptcha file require_once('captcha/recaptchalib.php'); // enter your public key $publickey = "6Ld5Df4SAAAAANFKozja9bUlDziJ92c31DDt1j6k"; // display recaptcha test fields echo recaptcha_get_html($publickey); ?> <input type="hidden" name="submitted" id="submitted" value="true" /> <?php // submit button ?> <input type="submit" value="Send Message" tabindex="5" id="submit" name="submit"> </form> <?php } // yay! that's all folks! ?>Attached Files form issue.txt 7.58KB 1 downloads Just a bit of background first: I have a contact form set up on one of my domains. It hasn't been updated in 7 years and recently I started getting about 3-8 spam messages daily through it. At some point I updated other sites with code that includes a CAPTCHA.
Out of sheer laziness, instead of recoding the contact form that was getting spammed, I just copied & pasted one of the updated forms and changed the necessary details like which e-mail address, URL, etc. Unfortunately, this hasn’t worked out properly.
For some reason the CAPTCHA image isn’t being displayed. I keep looking but can't find the error(s). Could someone please take a look at the code and tell me what went wrong? I’d be ever so grateful for any help! The code for the form itself: <form method="post" action="mail-e.php"> <p><input type="text" name="name" id="name" value="who are you?" size="25" /></p> <p><input type="text" name="email" id="email" value="you@whatever.bla" size="25" /></p> <p><input type="text" name="url" id="url" value="http://" size="25" /></p> <p><textarea name="comments" id="comments" rows="1" cols="20">Go on, then. Tell me a story, wingy!</textarea></p> <p><img src="http://echoing.org/captcha.php" alt="humanity check" /><br /> <input type="text" name="captcha" id="captcha" /> <br /> <p><input type="submit" name="submit" id="submit" value="sing to me" /> <input type="reset" name="reset" id="reset" value="out of key" /></p> </form>mail-e.php: <?php session_start(); //Encrypt the posted code field and then compare with the stored key if(md5($_POST['captcha']) != $_SESSION['key']) { die("Error: You must enter the code correctly"); }else{ echo 'You entered the code correctly'; } ?> <?php if (!isset($_POST['submit'])) { include('./header.php'); echo "<h1>HEY!!! You just encountered an error!</h1>\n <p>You don't belong here. <strong>Because it's <em>wrong</em>.</strong> Go back and try again, please.</p>"; include('./footer.php'); exit; } function cleanUp($data) { $data = strip_tags($data); $data = trim(htmlentities($data)); return $data; } $name = cleanUp($_POST['name']); $email = cleanUp($_POST['email']); $url = cleanUp($_POST['url']); $comments = cleanUp($_POST['comments']); if ((empty($name)) || (empty($email)) || (empty($comments))) { include('./header.php'); echo "<h2>Input Error! Looks like you missed some stuff.</h2>\n <p><strong>Name</strong>, <strong>e-mail</strong> and <strong>comments</strong> are required fields. Please fill them in and try again:</p>"; echo "<form action=\"mail-e.php\" method=\"post\"><p>"; echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />"; echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />"; echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />"; echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />"; echo "<img src=\"http://echoing.org/captcha.php\" alt=\"humanity check\" style=\"margin-bottom: 2px;\" /><br />"; echo "<input type=\"text\" name=\"captcha\" id=\"captcha\" /> <br />"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />"; echo "</p></form>"; include('./footer.php'); exit; } if (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",$email)) { include('./header.php'); echo "<h2>Input Error</h2>\n <p>That e-mail address you entered - \"$email\" - is <em>not</em> a valid electronic address. Please edit it and send it in again, please:</p>"; echo "<form action=\"mail-e.php\" method=\"post\"><p>"; echo "<input type=\"text\" name=\"name\" id=\"name\" value=\"$name\" /> Name<br />"; echo "<input type=\"text\" name=\"email\" id=\"email\" value=\"$email\" /> E-mail<br />"; echo "<input type=\"text\" name=\"url\" id=\"url\" value=\"$url\" /> Site URL<br />"; echo "<textarea name=\"comments\" id=\"comments\">$comments</textarea> Comments<br />"; echo "<img src=\"captcha.php\" alt=\"humanity check\" style=\"margin-bottom: 2px;\" /><br />"; echo "<input type=\"text\" name=\"captcha\" id=\"captcha\" /> <br />"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Send\" />"; echo "</p></form>"; include('./footer.php'); exit; } $email = preg_replace("([\r\n])", "", $email); $find = "/(content-type|bcc:|cc:)/i"; if (preg_match($find, $name) || preg_match($find, $email) || preg_match($find, $url) || preg_match($find, $comments)) { include('./header.php'); echo "<h1>Error</h1>\n <p>No meta/header injections, please.</p>"; include('./footer.php'); exit; } $recipient = "my email address is here"; $subject = "paint me a wish on a velvet sky"; $message = "Name: $name \n"; $message .= "E-mail: $email \n"; $message .= "URL: $url \n"; $message .= "Comments: $comments"; $headers = "From: a wish painted on the velvet sky \r\n"; $headers .= "Reply-To: $email"; if (mail($recipient,$subject,$message,$headers)) { include('./header.php'); echo "<<p>WOO HOO! Your message was successfully sent to me! I'll read it as soon as I can. I may even respond! Thanks for using the form, fruitcake :)</p>"; include('./footer.php'); } else { include('./header.php'); echo "<p>Something went awry. Your message didn't go through. Want to take another crack at it? Please do, I'd love to hear from you!</p>"; include('./footer.php'); } ?>captcha.php: <?php //Start the session so we can store what the code actually is. session_start(); //Now lets use md5 to generate a totally random string $md5 = md5(microtime() * mktime()); /* We dont need a 32 character long string so we trim it down to 5 */ $string = substr($md5,0,5); /* Now for the GD stuff, for ease of use lets create the image from a background image. */ $captcha = imagecreatefromjpeg("http://echoing.org/captcha.jpg"); /* Lets set the colours, the colour $line is used to generate lines. Using a blue misty colours. The colour codes are in RGB */ $black = imagecolorallocate($captcha, 0, 0, 0); $line = imagecolorallocate($captcha,233,239,239); /* Now to make it a little bit harder for any bots to break, assuming they can break it so far. Lets add some lines in (static lines) to attempt to make the bots life a little harder */ imageline($captcha,0,0,39,29,$line); imageline($captcha,40,0,64,29,$line); /* Now for the all important writing of the randomly generated string to the image. */ imagestring($captcha, 5, 20, 10, $string, $black); /* Encrypt and store the key inside of a session */ $_SESSION['key'] = md5($string); /* Output the image */ header("Content-type: image/jpeg"); imagejpeg($captcha); ?>I don’t know where it all went wrong as I’m using pretty much the same code without problems here, here and here. The form isn't being used presently (apart from the spam) but I am itching to know what the problem is. P.S. The link to the CAPTCHA image wasn’t always http://echoing.org/captcha.php in the code. On the other forms and initially with this one the code was ./captcha.php but I changed it in case that was the problem. Looks like it isn’t. Thanks in advance! I have a basic question for anyone that can help me. Ive added a captcha input field to the form below, as Im having problems with spam appearing on my testimonial page. 1) How can I prevent the form from being sent if the wrong or no answer is in the form field. 2) How can i have a message appear saying "Sorry wrong answer" if the from isnt sent for the above reason? add.php Code: [Select] <form method="post" action="process2.php" > <textarea rows="25" cols="100" wrap="physical" name="data"> </textarea> <input type="hidden" name="area" value="testimonial"/> What is 5+5? <input type="text" name="captcha"/> <input type="submit" value="Add "> </form> process2.php Code: [Select] <p class="add">Thankyou for submitting your testimonial;</br> <?php $data="<br><br>" . $_POST["data"]; ?><br /> <?php $area=$_POST["area"]; ?> <?php echo $data; ?></p> <?php mysql_query("UPDATE wheelchairwizard SET data = CONCAT(data, '$data') WHERE area = '$area'"); ?> </br> Return to the testimonial page - <a href="http://www.wheelchairwizard.co.uk/testimonials.php">click here</a> Hi, im trying to have a math captcha in my registration form, but having trouble with setting it up in my form. sorry for the large code. If i change the value of $_POST['Submit'] to something else like $_POST['Submit1'] and then same for the math image captcha then it works, but i would like it to work as part of the form, makes sense? lol right now the form just posts the value and doesnt check for captcha values! if someone could help me out here that would be great! thank you. Code: [Select] <?php if(isset($_POST['Submit'])){ if($_POST['Submit'] != $_SESSION['security_number']) { $error = ""; } else { $error = ""; } //NEED TO CHECK IF FIELDS ARE FILLED IN if( empty($_POST['name']) && (empty($_POST['email']))){ header("Location:Messages.php?msg=3"); exit(); } if( empty($_POST['pw1']) && (empty($_POST['pw2']))){ header( "Location:Messages.php?msg=4" ); exit(); } $name=$_POST['name']; $email=$_POST['email']; $pw1=$_POST['pw1']; $pw2=$_POST['pw2']; if("$pw1" !== "$pw2" ){ header( "Location:Messages.php?msg=5" ); exit(); } $ip = $_SERVER['REMOTE_ADDR']; //connect to the db server , check if uname exist include('config.php'); $query1=("Select * from user where email='$email'"); $result1= mysql_query($query1); $num1=mysql_num_rows($result1); if ($num1 > 0) {//Email already been used header( "Location:Messages.php?msg=11" ); exit(); }else{ $query=("Select * from user where uname='$name'"); $result= mysql_query($query); $num=mysql_num_rows($result); if ($num > 0) {//Username already exist header( "Location:Messages.php?msg=6" ); exit(); }else{ //if username does not exist insert user details $query=( "INSERT INTO user (uname, pw,email,date_joined,ip,level) VALUES ('$name',md5('$pw1'),'$email',NOW(),'$ip','Normal')"); if (@mysql_query ($query)) { header("location:login.php?reg=1"); exit; } } } mysql_close(); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><!-- InstanceBegin template="/Templates/Auth.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <!-- InstanceBeginEditable name="doctitle" --> <title>Registration</title> <!-- InstanceEndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- InstanceBeginEditable name="head" --> <!-- InstanceEndEditable --> <link href="styleLog.css" rel="stylesheet" type="text/css"> <script language="javascript" type="text/javascript"> function reloadCaptcha() { document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date(); } </script> </head> <body> <table width="100%" border="0" cellspacing="7" cellpadding="0"> <tr class="temptitle"> <td><!-- InstanceBeginEditable name="EditRegion4" -->New User Registration <!-- InstanceEndEditable --></td> </tr> <tr> <td><!-- InstanceBeginEditable name="EditRegion3" --> <form name="form1" action="register.php" method="post"> <table width="657" border="0"> <tr> <td width="122"><div align="left">Name</div></td> <td width="525"><input name="name" type="text" size="40"></td> </tr> <tr> <td><div align="left">Email</div></td> <td><input name="email" type="text" size="40"></td> </tr> <tr> <td><div align="left">Password</div></td> <td><input name="pw1" type="password" size="40"></td> </tr> <tr> <td ><div align="left">Confirm Password </div></td> <td><input name="pw2" type="password" size="40"></td> </tr> <tr> <td><img src="math_captcha/image.php" alt="Click to reload image" title="Click to reload image" id="captcha" onclick="javascript:reloadCaptcha()" /></td> <td><input type="text" name="Submit" value="what's the result?" onclick="this.value=''" /></td> <td> </tr> <tr> <td></td> <td> <input name="Submit" type="submit" value="Register"></td> </tr> </table> </form> <?=$error?> MOD EDIT: code tags added. Hi everyone,
I am unable to get the any of the form values to stay after submission with captcha.
My code is below.
Please help. Also the error of the validation doesnt display on submission
<!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} .success {color:#360; background-color:#FF0;} .fail {color:#F00; background-color:#FFF;) </style> </head> <body> <?php if (isset($_POST['submit'])){ $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $country = $_POST['country']; $comment = $_POST['comment']; $gender = $_POST['gender']; $to = "laxmon@wikigets.com"; $subject = "New contact form submission"; $message =" A visitor of WIKIGETS has submited a form onine\n\n $name\n\n $email\n\n $phone \n\n $country \n\n $gender\n\n $comment"; require_once('recaptchalib.php'); $privatekey = "6LdK8_YSAAAAAJYPJduOpxhsL4Cy86NgwpCSJCod"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { header ("Location:contact.php?s=2"); } else { mail($to,$subject,$message); header ("Location:contact.php?s=1"); } } ?> <? $country_options= array("select","Afghanistan", "Ã…Land Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia And Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, The Democratic Republic Of The", "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island And Mcdonald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic Of", "Iraq", "Ireland", "Isle Of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People'S Republic Of", "Korea, Republic Of", "Kuwait", "Kyrgyzstan", "Lao People'S Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States Of", "Moldova, Republic Of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Helena", "Saint Kitts And Nevis", "Saint Lucia", "Saint Pierre And Miquelon", "Saint Vincent And The Grenadines", "Samoa", "San Marino", "Sao Tome And Principe", "Saudi Arabia", "Senegal", "Serbia And Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia And The South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard And Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province Of China", "Tajikistan", "Tanzania, United Republic Of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad And Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks And Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis And Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe" ); // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = $countryErr = $phoneErr =""; $name = $email = $gender = $comment = $website = $phone = ""; $country =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address syntax is valid if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["phone"])) { $phone = ""; } else { $phone = test_input($_POST["phone"]); $phone = preg_replace('/\D/', '', $phone); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } $country2 = $_POST['country']; $country3= "select"; if($country2!= $country3) { $country=$country2; } else { $country1 = "Please select your country";} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>CONTACT US</h2> <p><?php $s=$_GET['s']; if($s=='1'){ Echo('<span class= "success"> Success!! An email has been sent to our web team. Please allow 24 hours for a response.</span>'); } else if ($s=='2') { Echo('<span class= "fail">Sorry! Please ensure to fill all feilds correctly</span>' ); } ?> </p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <p>Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr1;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr1;?></span> </p> <p>Phone Number:<input type="text" name="phone" value="<?php echo $phone;?>"> <span class="error"> <?php echo $phoneErr1;?></span> <br> <br> Country: <?php $item = 'select'; echo '<select name="country">'; foreach($country_options as $c) { $sel=''; // Set $sel to empty initially $tag = 'selected="selected"'; if(isset($_POST['country']) && $_POST['country'] == $c) // Here we check if the form has been posted so an error isn't thrown and then check it's value against $c { $sel = $tag; } elseif(!isset($_POST['country']) && $item == $c) // So that the $item doesn't override the posted value we need to check to make sure the form has NOT been submitted also in the { $sel = $tag; } echo '<option value="'.$c.'" '.$sel.'>'.$c.'</option>'; } echo '</select>'; ?> <span class="error">*<?php echo (isset($country1)) ? $country1 : '';?></span> <br><br> <!--Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr1;?></span> <br><br>--> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr1;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br> <?php require_once('recaptchalib.php'); $publickey = "6LdK8_YSAAAAACMvxVRzJ7ZNqjQ9nT_dU6fEZdHx"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <br> <input type="submit" name="submit" value="Submit"> </p> </form> </body> </html> Edited by laxi, 16 July 2014 - 12:45 PM. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=357935.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347360.0 why does this not display my hosting supports gd Code: [Select] <?php session_start(); create_image(); function create_image() { $rand = md5(rand(0, 9999999)); $vaule = substr ($rand, 10, 8); //widht and height is the width of the box $width = 150; $height = 30; //the will be ther sixe of the box $image = imagecreate($width, $height); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $grey = imagecolorallocate ($image, 132, 132, 132); $blue = imagecolorallocate ($image, 138, 197, 255); //the bg of the image imagefill($image, 0, 0, $blue); //imagetext imagestring($image, 5, 15, 7, $vaule, $black); //middle line and down line imageline($image, 0, $height/2, $width, $height/2, $grey); imageline($image, $width/2, 0, $width/2, $height, $grey); //hor line image($image, 0, 0, $width, $height, $grey); image($image, 0, $height, $width, 0, $grey); //desplay image imagepng($image); imagedestroy($image); //start session $_SESSION[captcha_key]; } ?> The following code is what I am trying to use for doing a form captcha style verification and all it is throwing back when I load the page is an image of the website address. Does anyone here know where I am going wrong? I have been at this all day and gotten nowhere. Thanks in advance <?php session_start(); $rndval = rand(1000, 9999); $_SESSION['rndnum'] = md5($rndval); $img = imagecreate(60, 30); $bgc = imagecolorallocate ($img, 255, 251, 205); $fontcolor = imagecolorallocate ($img, 0, 0, 0); imagestring ($img, 5, 5, 8, $rndval, $fontcolor); header('Content-type: image/jpeg'); imagejpeg($img); imagedestroy($img); ?> Hi, I am making a CAPTCHA image. I am pretty sure the code I have is correct, but I am getting these error messages when I run the script. I use GoDaddy for hosting. The font that I reference in the script is in the root directory with the script. Any ideas? Thanks, Craig ------------ Warning: imagefilledrectangle(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 19 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27 Warning: imagettftext() expects parameter 1 to be resource, null given in /home/content/68/6372768/html/captcha.php on line 30 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 35 Code: [Select] <?php session_start(); // Set some important CAPTCHA constants define('CAPTCHA_NUMCHARS', 6); // number of characters in pass-phrase define('CAPTCHA_WIDTH', 100); // width of image define('CAPTCHA_HEIGHT', 25); // height of image // Generate the random pass-phrase $pass_phrase = ""; for ($i = 0; $i < CAPTCHA_NUMCHARS; $i++) { $pass_phrase .= chr(rand(97, 122)); } // Store the encrypted pass-phrase in a session variable $_SESSION['pass_phrase'] = sha1($pass_phrase); // Create the image $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT); // Set a white background with black text and gray graphics $bg_color = imagecolorallocate($img, 255, 255, 255); // white $text_color = imagecolorallocate($img, 0, 0, 0); // black $graphic_color = imagecolorallocate($img, 64, 64, 64); // dark gray // Fill the background imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color); // Draw some random lines for ($i = 0; $i < 5; $i++) { imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Sprinkle in some random dots for ($i = 0; $i < 50; $i++) { imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Draw the pass-phrase string imagettftext($img, 18, 0, 5, CAPTCHA_HEIGHT - 5, $text_color, 'Courier New Bold.ttf', $pass_phrase); // Output the image as a PNG using a header header("Content-type: image/png"); imagepng($img); // Clean up imagedestroy($img); ?> I want to build a captcha from scratch, as I'm all about doing things myself, and I've proposed a nice idea on how I can achieve that, but I'm sort of lost... What I want to do is write a script that will generate a random string of both letters and numbers, with the ability to set a limit on how many characters are generated. Then, I want to store that string within a variable called "random_string". Once the user types in that code, their input would get captured in a separate php file and stored within a variable like so: $captcha_code = $_POST['catpcha_code']; Then, I would write a code to see if the user's input matches the random character string from the html: Code: [Select] <?php if ($random_string == $captcha_code) { mail($to, $subject, $body); } else { echo ("The code you entered did not match the captcha. Please go back and try again."); } ?> Is this possible? I haven't yet tried it myself, because I don't know how to generate random strings of characters, but I was just wondering if perhaps I'm on the right track? Any suggestions or advice is appreciated =) This is my first captcha script...it has 2 files, check.php and insert.php It works fine but I would like to hear your opinion what can I do to make it better? Is there any way that I can add random images ? Here is insert.php Code: [Select] <html> <body> <form action="check.php" method="post"> <img src="captcha.jpg"/> Insert captcha: <input type="text" name="cap"/> <input type="submit" value="submit"/> </form> </body> </html> here is check.php Code: [Select] <html> <body> <?php $cap= "flirc"; if ($_POST["cap"]==$cap) echo "Captcha is right!"; else echo " Captcha is wrong! "; ?> </body> </html>It is pretty basic, I know You can see it in action here Can anyone please take a quick glance at this form the captcha messages are not appearing correctly. The message keeps getting sent. Thank You Code: [Select] <?php if(($_SESSION['security_code'] != $_POST['security_code']) || (empty($_SESSION['security_code'])) ){ $to = "info@*******.com"; // change to your email address $name = htmlentities ($_POST['name']); $email = htmlentities ($_POST['email']); $phone = htmlentities ($_POST['phone']); $msg = htmlentities ($_POST['msg']); $d = date('l dS \of F Y h:i:s A'); $sub = "form to mail"; $headers = "From: $name <$email>\n"; $headers .= "Content-Type: text/plain; charset=iso-8859-1\n"; $mes = "phone: ".$phone."\n"; $mes .= "Message: ".$msg."\n"; $mes .= "Name: ".$name."\n"; $mes .= 'Email: '.$email."\n"; $mes .= 'Date & Time: '.$d; { mail($to, $sub, $mes, $headers); } echo "<p> </p><p> </p><p> </p><br />CAPTCHA CODE does not match! <p> </p><p> </p><a href='javascript:javascript:history.go(-1)'>Click here to go back to previous page</a>"; } else echo "THANK YOU"; ?> hi ,frds i am getting trouble . here is my problem captcha is working fine in firefox 3.6.16 but not in IE6 help me frds. Hello everybody, I am new to these forums and registered due to my problems which has been annoying me all the evening... I've been googling for 3 hours and still haven't found a proper answer. The situation is: I started to use session in my page. <?php ini_set('session.use_cookies', 0); ini_set('session.use_only_cookies', 0); ini_set('session.name', 'sid'); ini_set('session.auto_start', 0); ini_set('session.use_trans_sid', 1); session_start(); ?> these lines are included in, let's say, my register.php file. (please, don't recommend me cookies as i'm developing a site for mobiles) And then, there is a form: <?php echo '<form action="register.php?sid='.session_id().'" method="POST"> Įveskite kodą:<br/> <input class="input" type="text" name="captcha" maxlength="4"/><br/> <img id="captcha" src="captcha.php?sid='.session_id().'" /><br/> <input type="submit" name="submit" value="Registruotis" /><br/> </form>';?> although captcha is shown, when I submit the form and i have to check inputs I get this error: Notice: Undefined index: randomnr2 in C:\Program Files\EasyPHP-5.3.3.1\www\new\register.php on line 144 Well, my captcha.php file: <?php $randomnr = rand(1000, 9999); $_SESSION['randomnr2'] = $randomnr; $im = imagecreatetruecolor(100, 38); $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 150, 150, 150); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 200, 35, $black); //path to font - this is just an example you can use any font you like: $font = dirName(__FILE__).'/font/karate/Karate.ttf'; imagettftext($im, 20, 4, 22, 30, $grey, $font, $randomnr); imagettftext($im, 20, 4, 15, 32, $white, $font, $randomnr); //prevent caching on client side: 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-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header ("Content-type: image/gif"); imagegif($im); imagedestroy($im); ?> Any ideas? Thanks in advance. Hi I have a script below which I have put together from a couple of other scripts which simply adds an email address to a database for a newsletter and sends an email to the owner and to the user it then shows a success page. The script checks that the email is valid and there is also a captcha. The script works in that it only send out the emails if the captcha etc is entered correctly but the email is being added to the database regardless of whether the capture is correct or not. I was proud of myself for getting this far but would love some instruction on what I have missed and how to stop the email adding to the database unless it has passed the captcha. Below you will see the script. The commented out sections are parts of the old script I don't use. <?php require('includes/application_top.php'); require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_TESTING); $error = false; if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) { //$name = tep_db_prepare_input($HTTP_POST_VARS['name']); $email_address = tep_db_prepare_input($HTTP_POST_VARS['email']); //$enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']); if (tep_validate_email($email_address) == false) { $error = true; $messageStack->add('testing', ENTRY_EMAIL_ADDRESS_CHECK_ERROR); } //CAPTHCA CODE start require(DIR_WS_FUNCTIONS . 'capcha_code.php'); $code_query = tep_db_query("select code from capcha_code where oscsid = '" . tep_session_id($HTTP_GET_VARS[tep_session_name()]) . "'"); $code_array = tep_db_fetch_array($code_query); $code = $code_array['code']; tep_db_query("DELETE FROM " . TABLE_CAPCTHA_CODE . " WHERE oscsid='" . $vvcode_oscsid . "'"); //remove the visual verify code associated with this session to clean database and ensure new results $user_entered_code = $HTTP_POST_VARS['capcha_code']; if (!(strcasecmp($user_entered_code, $code) == 0)) { //make the check case insensitive $error = true; $messageStack->add('testing', CAPCTHA_CODE_ENTRY_ERROR); } //CAPTHCA CODE stop /* testing sign up start */ if (isset($HTTP_POST_VARS['testing_sign_up'])) { $testing_query = tep_db_query("select testing_id_number from " . TABLE_TESTING_SIGN_UP . " where testing_email_address = '" . tep_db_input($email_address) . "'"); if(tep_db_num_rows($testing_query) == 0) { $sql_data_array = array('testing_email_address' => $email_address, 'testing_firstname' => "", 'testing_lastname' => ""); tep_db_perform(TABLE_TESTING_SIGN_UP, $sql_data_array); } } /* testing sign up end */ if ($error == false) { tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_address,STORE_OWNER_EMAIL_ADDRESS); tep_mail(MESSAGE_TEXT, $email_address, CUSTOMER_SUBJECT, NUMBER_ONE, STORE_OWNER_EMAIL_ADDRESS); tep_redirect(tep_href_link(FILENAME_TESTING, 'action=success')); } } $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_TESTING)); ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> </head> <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"> <!-- header //--> <?php require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <!-- body //--> <table border="0" width="100%" cellspacing="3" cellpadding="3"> <tr> <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2"> <!-- left_navigation //--> <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?> <!-- left_navigation_eof //--> </table></td><!-- body_text //--> <td width="100%" valign="top"><?php echo tep_draw_form('testing', tep_href_link(FILENAME_TESTING, 'action=send')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td class="pageHeading"><?php echo HEADING_TITLE; ?></td><td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_contact_us.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td></tr> </table> </td></tr><td class="main"><?php echo INFORMATION_TEXT; ?></td> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td></tr> <?php if ($messageStack->size('testing') > 0) { ?> <tr> <td><?php echo $messageStack->output('testing'); ?></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <?php } if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'success')) { ?> <tr> <td class="main" align="left"><?php echo tep_image(DIR_WS_IMAGES . 'clever.gif', HEADING_TITLE, '0', '0', 'align="left"') . TEXT_COMPLETE; ?></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td> <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <?php } else { ?> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2" > <!--<tr> <td class="main"><?php echo ENTRY_NAME; ?></td> </tr> <tr> <td class="main"><?php echo tep_draw_input_field('name'); ?></td> </tr>//--> <tr><td class="main"><?php echo INSTRUCTIONS_TEXT; ?></td></tr> <tr> <td class="main"><?php echo ENTRY_EMAIL; ?> <?php echo tep_draw_input_field('email'); ?></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <!--<tr> <td class="main"><?php echo ENTRY_ENQUIRY; ?></td> </tr> <tr> <td><?php echo tep_draw_textarea_field('enquiry', 'soft', 50, 15, $infotext); ?></td> </tr>//--> <!-- CAPTHCA CODE-- START--> <tr> <td class="main"><?php echo CAPCTHA_CODE_CATEGORY; ?></td> </tr> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" cellspacing="2" cellpadding="2"> <tr> <td class="main"><?php echo CAPCTHA_CODE_TEXT_INSTRUCTIONS; ?></td> <td class="main"> <?php // ----- begin garbage collection -------- tep_db_query("DELETE FROM " . TABLE_CAPCTHA_CODE . " WHERE dt < DATE_SUB(NOW(), INTERVAL 5 HOUR)"); // ----- end garbage collection -------- //can replace the following loop with $capcha_code = substr(str_shuffle (CAPCTHA_CODE_CHARACTER_POOL), 0, rand(3,4)); if you have PHP 4.3 $capcha_code = ""; for ($i = 1; $i <= rand(3,4); $i++){ $capcha_code = $capcha_code . substr(CAPCTHA_CODE_CHARACTER_POOL, rand(0, strlen(CAPCTHA_CODE_CHARACTER_POOL)-1), 1); } $vvcode_oscsid = tep_session_id($HTTP_GET_VARS[tep_session_name()]); tep_db_query("DELETE FROM " . TABLE_CAPCTHA_CODE . " WHERE oscsid='" . $vvcode_oscsid . "'"); $sql_data_array = array('oscsid' => $vvcode_oscsid, 'code' => $capcha_code); tep_db_perform(TABLE_CAPCTHA_CODE, $sql_data_array); $capcha_code = ""; echo('<img src="' . FILENAME_CAPCTHA_CODE_DISPLAY . '?vvc=' . $vvcode_oscsid . '"'); ?> </td> <td class="main"><?php echo CAPCTHA_CODE_BOX_IDENTIFIER; ?></td> <td class="main"><?php echo tep_draw_input_field('capcha_code'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <!-- testing sign up start//--> <TD WIDTH="100%"> <tr> <td class="main" align="right"><?php echo ENTRY_TESTING_SIGN_UP; ?> <?php echo tep_draw_checkbox_field('testing_sign_up', '1', true); ?> </td></tr> <!--testing sign up end //--> <!-- CAPTHCA CODE-- STOP --> <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> </table></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <tr> <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"> <tr class="infoBoxContents"> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> <td align="right"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td> <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> </tr> </table></td> </tr> </table></td> </tr> <?php } ?> </table></form></td> <!-- body_text_eof //--> <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2"> <!-- right_navigation //--> <?php require(DIR_WS_INCLUDES . 'column_right.php'); ?> <!-- right_navigation_eof //--> </table></td> </tr> </table> <!-- body_eof //--> <!-- footer //--> <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> <br> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> I'm trying to login to a vBulletin forum using a captcha login. I am, however, not able to download the captcha image. This is the result I get when I try to get the captcha: So how do I get the captcha image? This is my current login code: Code: [Select] <?php $user='username'; $pass='password'; $md5Pass = md5($pass); $data = "do=login&vb_login_md5password=$md5Pass&vb_login_md5password_utf=$md5Pass&vb_login_username=$user&cookieuser=1"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, "http://www.****.com/login.php?do=login"); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt ($ch, CURLOPT_TIMEOUT, '10'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $store = curl_exec ($ch); curl_close($ch); echo $store; ?> Maybe the site looks for a cookie and only shows the captcha if it finds the cookie file? |