$captchaSecret = "OASDOIJQWOIJDASDOI"; $emailSecret = "AOSIDJOIQLSDKFMl"; /* Begin easycaptcha validate code */ if (isset($_REQUEST['confirm_code'])) { if ( isset($_COOKIE['Captcha']) ) { list($Hash, $Time) = explode('.', $_COOKIE['Captcha']); $correctHash = md5( $captchaSecret. $_REQUEST['confirm_code']. $_SERVER['REMOTE_ADDR']. $Time ); if ( $correctHash != $Hash ) { print "Captcha code is wrong."; } elseif( (time() - 30) > $Time) { print "Captcha code is only valid for 30 seconds"; } else { print "Captcha code entered correctly"; // Send a validation e-mail now $thisURL = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; $emailHash = md5($emailSecret. $_GET['email']); $emailToken = substr($emailHash,0,5). '%7C' .urlencode($_GET['email']); $validateEmailURL = $thisURL.'?emailToken='.$emailToken; mail( $_GET['email'], 'Email validation', "Please click this link to verify your e-mail address: ".$validateEmailURL."" ); die('A validation e-mail was sent to the address your provided. Please open the link in that e-mail to continue registration'); } } else { print "No captcha cookie given. Make sure cookies are enabled."; } /* End easycaptcha validate code */ } elseif ( isset($_REQUEST['emailToken']) ) { /* Begin easyregister validate code */ list($key, $email) = explode('|',$_REQUEST['emailToken'],2); $correctEmailHash = md5($emailSecret.$email); if ( $key !== substr($correctEmailHash,0,5) ) { die("An invalid e-mail token was given, please try again"); } else { // Set the email-token to a cookie so that he'll remain validated when he submits the registration form setcookie('emailToken', $_REQUEST['emailToken']); } // The users e-mail is validated; now we can start processing their registration data if ( ! isset($_REQUEST['registrationForm']) ) { // No registration form data entered yet, show the form print 'You have confirmed your e-mail address. Please fill out the following registration form:'; require('registrationForm.php'); } else { // Registration form data present, process the registration and create the validated user require('processRegistrationForm.php'); } } else { // This person didn't give a proper captcha code, or is just starting the registration process. // Prompt them to enter a captcha code and their e-mail address for validation print '
'; // Easyregister form code print 'E-mail address:
'; /* Begin easycaptcha form code */ print '
Enter the code from the above image:
'; print '
'; /* End easycaptcha form code */ }