Proble captcha code toujours valide!
Posté : 04 févr. 2013, 18:57
Salut je dois avoir un prob dans mon code mon captcha est toujours valide quelqu un aurrait une idée svp?
<?php
/*
Template Name: Contact Form
*/
?>
<?php
//Le formulaire sera soumis,
if(isset($_POST['submitted'])) {
//si l'attrape nigaud est vide
if(trim($_POST['checking']) !== '') {
$captchawarning = true;
} else {
//si le nom est rentré correctement
if(trim($_POST['contactName']) === '') {
$namewarning = ' Indiquez votre nom :';
$haswarning = true;
} else {
$name = trim($_POST['contactName']);
}
//si l'email est rentré correctement
if(trim($_POST['email']) === '') {
$emailwarning = ' Indiquez une adresse e-mail valide :';
$haswarning = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$emailwarning = ' Adresse e-mail invalide!';
$haswarning = true;
} else {
$email = trim($_POST['email']);
}
//si il y a un commentaire
if(trim($_POST['comments']) === '') {
$commentwarning = ' Entrez votre message :';
$haswarning = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
// //si l'utilisateur a entré un code correctement
[color=#FF0000] if (trim($_POST['code']) === '') {
$codewarning = ' Aucun code :';
$haswarning = true;
$code = strtoupper($_POST['code']);
if( md5($code) == $_SESSION['captcha'] ){
$codewarning = ' Erreur code :';
$haswarning = true;
} else {
$code = trim($_POST['code']);
}
}
[/color]
//et donc envoi du mail si aucune erreur
if(!isset($haswarning)) {
$emailTo = '[email protected]';
$subject = 'Message de '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Nom: $name \n\nEmail: $email \n\nMessage: $comments";
$headers = 'De : mon site <'.$emailTo.'>' . "\r\n" . 'Répondre à: ' . $email;
mail($emailTo, $subject, $body, $headers);
if($sendCopy == true) {
$subject = 'Formulaire de contact';
$headers = 'De : <[email protected]>';
mail($email, $subject, $body, $headers);
}
$emailSent = true;
}
}
} ?>
<?php get_header(); ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/contact-form.js"></script>
<div id="me-contacter">
<div id="forms-top"><h1>Formulaire de contact</h1></div>
<?php if(isset($emailSent) && $emailSent == true) { ?>
<div class="thanks">
<h1>Merci, <?=$name;?></h1>
<p>votre e-mail a été envoyé avec succès.</p>
<div id="thanks-bot"></div>
</div>
<?php } else { ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if(isset($haswarning) || isset($captchawarning)) { ?>
<p class="erreur">Erreur veuillez recommencer<p>
<?php } ?>
<form action="<?php the_permalink(); ?>" method="post">
<ol class="forms">
<li><label for="contactName">Nom</label>
<?php if($namewarning != '') { ?>
<span class="warning"><?=$namewarning;?></span>
<?php } ?>
<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />
</li>
<li><label for="email">E-mail</label>
<?php if($emailwarning != '') { ?>
<span class="warning"><?=$emailwarning;?></span>
<?php } ?>
<input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="requiredField email" />
</li>
<li class="textarea"><label for="commentsText">Message</label>
<?php if($commentwarning != '') { ?>
<span class="warning"><?=$commentwarning;?></span>
<?php } ?>
<textarea name="comments" id="commentsText" rows="20" cols="30" class="requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
</li>
<li class="code"><label for="code">Code</label>
<?php if($codewarning != '') { ?>
<span class="warning"><?=$codewarning;?></span>
<?php } ?>
<input type="text" name="code" id="code" value="<?php if(isset($_POST['code'])) echo $_POST['code'];?>" class="requiredField code" />
</li>
<li class="inline"><label for="sendCopy">Recevoir une copie du message</label><input type="checkbox" name="sendCopy" id="sendCopy" value="true"<?php if(isset($_POST['sendCopy']) && $_POST['sendCopy'] == true) echo ' checked="checked"'; ?> /></li>
<li class="screenreader"><label for="checking" class="screenreader"></label><input type="text" name="checking" id="checking" class="screenReader" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" /></li>
<li class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" /><button type="submit"><span>envoyer</span></button></li>
</ol>
</form>
<div id="forms-bot"><h1></h1></div>
<div id="captcha"><!-- Image dynamique -->
<img src="captcha.php" alt="Captcha" id="captcha" />
</div>
<div id="captchareload"><!-- (JavaScript) Recharge l'image car elle n'existe pas dans le cache du navigateur, grâce à l'id généré -->
<img src="reload.png" alt="Recharger l'image" title="Recharger l'image" style="cursor:pointer;position:relative;top:-7px;" onclick="document.images.captcha.src='captcha.php?id='+Math.round(Math.random(0)*1000)" /><!-- (JavaScript) Recharge l'image car elle n'existe pas dans le cache du navigateur, grâce à l'id généré -->
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php } ?>
<?php get_footer(); ?>