Bonjour, je viens de mettre en ligne un
formulaire de contact réalisé en PHP sur mon site perso.
J'ai effectué tous les tests préalables
offline et tout fonctionnait parfaitement.
La version
online se comporte quant à elle étrangement : l'envoie du mail fonctionne quel que soit le captcha renseigné, qu'il soit bon
ou mauvais.
Avec des conditions telles que je les ai codées, ça ne devrait pas être possible.
Mon formulaire :
* en début de page session_start();
<form method="post" action="" >
<fieldset>
<legend>Formulaire de contact</legend>
<div id="main">
<?php
if ((isset($_POST['mail'])) &&
(isset($_POST['subject'])) &&
(isset($_POST['body'])) &&
(isset($_POST['captcha'])) &&
(isset($_SESSION['captcha'])))
{
$mail = htmlentities($_POST['mail'], ENT_QUOTES);
$subject = htmlentities($_POST['subject'], ENT_QUOTES);
$body = nl2br(htmlentities($_POST['body'], ENT_QUOTES));
$captcha = htmlentities($_POST['captcha'], ENT_QUOTES);
if ((!empty($_POST['mail'])) &&
(!empty($_POST['subject'])) &&
(!empty($_POST['body'])) &&
(!empty($_POST['captcha'])) &&
(!empty($_SESSION['captcha'])))
{
if ($captcha == $_SESSION['captcha'])
{
if (preg_match("!^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$!", $mail))
{
$to = '[email protected]';
$header = "From: $mail \n";
$header .= "X-Priority: 1 \n";
$header .= "Content-Type: text/html \n";
if (mail( $to , $subject , $body, $header ))
{
echo '<p class="warning-right"><strong>Votre message à été envoyé !</strong></p>';
}
else {
echo '<p class="warning-wrong"><strong>Une erreur est survenue, merci de réessayer plus tard.</strong></p';
}
}
else {
echo '<p class="warning-wrong"><strong>L\'adresse e-mail que vous avez entrée n\'est pas valide.</strong></p>';
}
}
else {
echo '<p class="warning-wrong"><strong>Le captcha n\'est pas bon.</strong></p>';
session_destroy();
}
}
else {
echo '<p class="warning-wrong"><strong>Tous les champs ne sont pas remplis.</strong></p>';
}
}
?>
<p><label for="mail">Votre e-mail :</label><input type="text" name="mail" id="mail" value="<?php echo $mail; ?>" /></p>
<p><label for="subject">Sujet :</label><input type="text" name="subject" id="subject" value="<?php echo $subject; ?>" /></p>
<p><label for="body">Texte :</label><textarea id="body" name="body"><?php echo $body; ?></textarea></p>
</div>
<fieldset>
<legend>Captcha anti-spam</legend>
<p>
Vous devez recopier les chiffres que vous voyez dans l'image ci-dessous.<br/>
Cette image ne contient que des chiffres, il n'y a pas de lettre.
</p>
<p style="margin: 10px;"><img src="../includes/captcha.php" alt="Captcha" /></p>
<p><label for="captcha">Cpatcha :</label><input type="text" name="captcha" id="captcha" /></p>
</fieldset>
<p><input type="submit" value="Envoyer" id="submit" /></p>
</fieldset>
</form>
Mon captcha :
<?php
session_start();
function nombre($n)
{
return str_pad(mt_rand(0,pow(10,$n)-1),$n,'0',STR_PAD_LEFT);
}
function image($mot)
{
$largeur = strlen($mot) * 10;
$hauteur = 20;
$img = imagecreate($largeur, $hauteur);
$blanc = imagecolorallocate($img, 255, 255, 255);
$noir = imagecolorallocate($img, 0, 0, 0);
$milieuHauteur = ($hauteur / 2) - 8;
imagestring($img, 6, strlen($mot) /2 , $milieuHauteur, $mot, $noir);
imageline($img, 2, $milieuHauteur + 8, $largeur - 2, $milieuHauteur + 8, $noir);
imageline($img, 2,mt_rand(2,$hauteur), $largeur - 2, mt_rand(2,$hauteur), $noir);
imagepng($img);
imagedestroy($img);
}
function captcha()
{
$mot = nombre(5);
$_SESSION['captcha'] = $mot;
image($mot);
}
header("Content-type: image/png");
captcha();
?>
Auriez-vous une idée concernant l'origine de ce problème ?
Merci d'avance.
Bonjour, je viens de mettre en ligne un [url=http://tinyurl.com/dlj2h4]formulaire de contact[/url] réalisé en PHP sur mon site perso.
J'ai effectué tous les tests préalables [b]offline[/b] et tout fonctionnait parfaitement.
La version [b]online[/b] se comporte quant à elle étrangement : l'envoie du mail fonctionne quel que soit le captcha renseigné, qu'il soit bon [b]ou mauvais[/b].
Avec des conditions telles que je les ai codées, ça ne devrait pas être possible.
Mon formulaire :
[php]* en début de page session_start();
<form method="post" action="" >
<fieldset>
<legend>Formulaire de contact</legend>
<div id="main">
<?php
if ((isset($_POST['mail'])) &&
(isset($_POST['subject'])) &&
(isset($_POST['body'])) &&
(isset($_POST['captcha'])) &&
(isset($_SESSION['captcha'])))
{
$mail = htmlentities($_POST['mail'], ENT_QUOTES);
$subject = htmlentities($_POST['subject'], ENT_QUOTES);
$body = nl2br(htmlentities($_POST['body'], ENT_QUOTES));
$captcha = htmlentities($_POST['captcha'], ENT_QUOTES);
if ((!empty($_POST['mail'])) &&
(!empty($_POST['subject'])) &&
(!empty($_POST['body'])) &&
(!empty($_POST['captcha'])) &&
(!empty($_SESSION['captcha'])))
{
if ($captcha == $_SESSION['captcha'])
{
if (preg_match("!^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$!", $mail))
{
$to = '
[email protected]';
$header = "From: $mail \n";
$header .= "X-Priority: 1 \n";
$header .= "Content-Type: text/html \n";
if (mail( $to , $subject , $body, $header ))
{
echo '<p class="warning-right"><strong>Votre message à été envoyé !</strong></p>';
}
else {
echo '<p class="warning-wrong"><strong>Une erreur est survenue, merci de réessayer plus tard.</strong></p';
}
}
else {
echo '<p class="warning-wrong"><strong>L\'adresse e-mail que vous avez entrée n\'est pas valide.</strong></p>';
}
}
else {
echo '<p class="warning-wrong"><strong>Le captcha n\'est pas bon.</strong></p>';
session_destroy();
}
}
else {
echo '<p class="warning-wrong"><strong>Tous les champs ne sont pas remplis.</strong></p>';
}
}
?>
<p><label for="mail">Votre e-mail :</label><input type="text" name="mail" id="mail" value="<?php echo $mail; ?>" /></p>
<p><label for="subject">Sujet :</label><input type="text" name="subject" id="subject" value="<?php echo $subject; ?>" /></p>
<p><label for="body">Texte :</label><textarea id="body" name="body"><?php echo $body; ?></textarea></p>
</div>
<fieldset>
<legend>Captcha anti-spam</legend>
<p>
Vous devez recopier les chiffres que vous voyez dans l'image ci-dessous.<br/>
Cette image ne contient que des chiffres, il n'y a pas de lettre.
</p>
<p style="margin: 10px;"><img src="../includes/captcha.php" alt="Captcha" /></p>
<p><label for="captcha">Cpatcha :</label><input type="text" name="captcha" id="captcha" /></p>
</fieldset>
<p><input type="submit" value="Envoyer" id="submit" /></p>
</fieldset>
</form>[/php]
Mon captcha :
[php]<?php
session_start();
function nombre($n)
{
return str_pad(mt_rand(0,pow(10,$n)-1),$n,'0',STR_PAD_LEFT);
}
function image($mot)
{
$largeur = strlen($mot) * 10;
$hauteur = 20;
$img = imagecreate($largeur, $hauteur);
$blanc = imagecolorallocate($img, 255, 255, 255);
$noir = imagecolorallocate($img, 0, 0, 0);
$milieuHauteur = ($hauteur / 2) - 8;
imagestring($img, 6, strlen($mot) /2 , $milieuHauteur, $mot, $noir);
imageline($img, 2, $milieuHauteur + 8, $largeur - 2, $milieuHauteur + 8, $noir);
imageline($img, 2,mt_rand(2,$hauteur), $largeur - 2, mt_rand(2,$hauteur), $noir);
imagepng($img);
imagedestroy($img);
}
function captcha()
{
$mot = nombre(5);
$_SESSION['captcha'] = $mot;
image($mot);
}
header("Content-type: image/png");
captcha();
?>[/php]
Auriez-vous une idée concernant l'origine de ce problème ?
Merci d'avance.