What's wrong with my simple captcha php script?
I also have session_start();
at the top of my index page, its not working!
<?php
if(isset($_REQUEST['Submit'])){
$key=substr($_SESSION['key'],0,5);
$captcha = $_REQUEST['captcha'];
if($captcha=!$key){
exit();
}
$EmailFrom = "****";
$EmailTo = "****";
$Subject = "****";
$contactname = Trim(stripslashes($_POST['contactname']));
$companyname = Trim(stripslashes($_POST['companyname']));
$username = Trim(stripslashes($_POST['username']));
$phone = Trim(stripslashes($_POST['phone']));
$email = Trim(stripslashes($_POST['email']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=../404.php/\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Contact Name: ";
$Body .= $contactname;
$Body .= 开发者_如何学运维"\n";
$Body .= "Company Name: ";
$Body .= $companyname;
$Body .= "\n";
$Body .= "Preferred Username: ";
$Body .= $username;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print '<script type="text/javascript">';
print 'alert("Your Submission will be reviewed by an Admin and you will receive an email shortly")';
print '</script>';
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://****.com/****/\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=../404.php/\">";
}
?>
You are missing a }
at the end (before ?>
)
Be sure to indent your code correctly to easily catch these errors.
Add another curly bracket at the end and it should be ok i think
You are not closing the curly bracket for your top level if statement if(isset($_REQUEST['Submit'])){
OR based on how you want your flow you can remove the curly bracket from
if($captcha=!$key){
exit();
So that it becomes
if($captcha!=$key)
exit();
Notice that i changed =!
to !=
as well
精彩评论