PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi guys, im fixing a captcha, but im having some trouble, basically is all ok, i have the page contacts.php and contact_send.php that is where it takes the action.
But i have a problem.
When i put a bad captcher number this goes to the page of contact_send.php and says, "Wrong code", than i have to go back in a browser in do it again, but i want it to make that when i make a bad entry code, it appears like a javascript message saying "wrong code". And redirects me to the incial page to correct that is contacts.php
the code i put it in the contact_send.php is this one.
if(md5($_POST['code']) != $_SESSION['key']) {
echo "<script language='javascript'>alert('Wrong Code!')</script>";
echo "Please go <a href='javascript:history.go(-1);'><strong>back</strong></a> and use a proper address, then re-submit the form."; //will save all the data that was entered in the form when they go back.
//or use this instead, but use only one of them
echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><html><head><meta http-equiv='REFRESH' content='0;url=http://whereveryouwant.com'>"; //will not save the data the user put in
}else{
//do what you want when the code is correct here
}
There is no need to use the die("Wrong Code"); if you use the before mentioned code and add all of your code in the else section it will work. Use this...
That will grab the $_POST data, check it with the first if statement. if the first statement "if(md5($_POST['code']) != $_SESSION['key'])" is true it will stop the code and give an alert, it will only send the email if it gets past that first statement. The above code will do exactly what you want, try it yourself.
<?php
session_start();
if(md5($_POST['code']) != $_SESSION['key']) {
echo "<script language='javascript'>alert('Wrong Code!')</script>";
echo "Please go <a href='javascript:history.go(-1);'><strong>back</strong></a> and use a proper address, then re-submit the form."; //will save all the data that was entered in the form when they go back.
//or use this instead, but use only one of them
echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'><html><head><meta http-equiv='REFRESH' content='0;url=http://DOMAIN.COM/contato.php'>"; //will not save the data the user put in
}else{
$datahora = "DATA: <B>" . date("d/m/y - H:i:s") . "</B><BR><BR>";
foreach ($_POST as $campo => $valor) {
if (($campo == 'imageField2_x') or ($campo == 'imageField2_y') or ($campo == 'button') or ($campo == 'subimit_y')) {}else {
if ($valor <> '') {
$campo = str_replace("_", " ",$campo);
$campos .= strtoupper($campo) . ": <b>" . $valor . "</b><Br>";
}
}
}
$www = "WWW.DOMAIN.COM";
$assunto = "CONTACTO - DOMAIN - " . $www;
$conteudo = "CONTACTO - Domain<br><br>" . $datahora . utf8_decode($campos) . "<br>" . $www;
$para = "email";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Domain <geral@domain.com>\r\n";
$headers .= "Reply-To: ".$_POST['email']."\r\n";
if ((mail($para,$assunto,$conteudo,$headers)) == true){ ?>
<script>
alert('Info send sucess!');
window.location = 'contato.php';
</script>
<? } ?>
} <------error here