Verification code php

Résolu/Fermé
siegfrield Messages postés 4 Date d'inscription samedi 7 février 2009 Statut Membre Dernière intervention 9 septembre 2011 - Modifié par siegfrield le 13/09/2011 à 16:37
 Utilisateur anonyme - 8 sept. 2011 à 07:47
Bonjour,

Je tente d'insérer un captcha dans un formulaire. Mais cela ne fonctionne pas. J'ai "image de protection" qui apparait a la place de l'image du captcha.

Ai-je fait une erreur dans le code ?

Merci de votre aide.

Dans ma page contact.php j'ai ce code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
<style type="text/css">
<!--
#form {
width: 800px;
margin-right: auto;
margin-left: auto;
height: auto;
}
-->
</style>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="form">
<form action="traitement.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="24%">Société :</td>
<td width="76%"><span id="sp_societe">
<input name="societe" type="text" id="societe" tabindex="1" size="30" />
</span></td>
</tr>
<tr>
<td>Civilité :</td>
<td><select name="civilite" size="1" id="civilite" tabindex="1">
<option>Choisissez</option>
<option>Mlle</option>
<option>Mme</option>
<option>M.</option>
</select></td>
</tr>
<tr>
<td>Nom :</td>
<td><span id="sp_nom">
<input name="nom" type="text" id="nom" tabindex="1" size="50" />
<span class="textfieldRequiredMsg">Une valeur est requise.</span></span></td>
</tr>
<tr>
<td>Prénom :</td>
<td><span id="sp_prenom">
<input name="prenom" type="text" id="prenom" tabindex="1" size="50" />
<span class="textfieldRequiredMsg">Une valeur est requise.</span></span></td>
</tr>
<tr>
<td>Mél. :</td>
<td><span id="sp_mail">
<input name="mail" type="text" id="mail" tabindex="1" size="50" />
<span class="textfieldRequiredMsg">Une valeur est requise.</span><span class="textfieldInvalidFormatMsg">Format non valide.</span></span></td>
</tr>
<tr>
<td>URL :</td>
<td><span id="sp_url">
<input name="url" type="text" id="url" tabindex="1" value="[http://]" size="50" />
</span></td>
</tr>
<tr>
<td>Objet :</td>
<td><span id="sp_objet">
<input name="objet" type="text" id="objet" tabindex="1" size="50" />
<span class="textfieldRequiredMsg">Une valeur est requise.</span></span></td>
</tr>
<tr>
<td>Message :</td>
<td><span id="sp_message">
<textarea name="message" cols="80" rows="5" id="message" tabindex="1"></textarea>
<span class="textfieldRequiredMsg">Une valeur est requise.</span></span></td>
</tr>
<tr>
<td>Pièce jointe :</td>
<td><input type="file" name="parcourir" id="parcourir" tabindex="1" /></td>
</tr>
<tr>
<td>Comment avez-vous connu...?</td>
<td><select name="decouverte" size="1" id="decouverte" tabindex="1">
<option selected="selected">Sélectionner</option>
<option>Un ami</option>
<option>Un contact professionnel</option>
<option>Publicité</option>
<option>Démarchage</option>
<option>Autre</option>
</select></td>
</tr>
<tr>
<td>Code de vérification :</td>
<td><input type="text" name="verif" size="10" maxlength="6" />
<img src="captcha.php" alt="image de protection" align="absmiddle" />
</td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="envoyer" id="envoyer" value="Envoyer" tabindex="1" />
<input type="reset" name="effacer" id="effacer" value="Effacer" tabindex="1" />
</div></td>
</tr>
</table>
</form>
</div>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sp_societe", "none", {validateOn:["blur", "change"], isRequired:false});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sp_nom", "none", {validateOn:["blur", "change"]});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sp_prenom", "none", {validateOn:["blur", "change"]});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sp_mail", "email", {validateOn:["blur", "change"]});
var sprytextfield5 = new Spry.Widget.ValidationTextField("sp_url", "none", {validateOn:["blur", "change"], isRequired:false});
var sprytextfield6 = new Spry.Widget.ValidationTextField("sp_objet", "none", {validateOn:["blur", "change"]});
var sprytextfield7 = new Spry.Widget.ValidationTextField("sp_message", "none", {validateOn:["blur", "change"]});
//-->
</script>
</body>
</html>

Puis dans ma page captcha.php j'ai celui-ci :


<?php
session_start();
$liste="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$code=";
while(strlen($code)!=6){
$code.=$liste[rand(0,36)];
}
$_SESSION['code']=$code;
$img=imagecreate(70,20) or die ("Problème de création GD");
$background_color=imagecolorallocate($img,238,238,238);
$ecriture_color=imagecolorallocate($img,0,0,0);
$code_police=5;
header('Expires: Mon, 26 Jul 1997 05h00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header("Content-type: image/jpeg");
imageString($img,$code_police,(70-imageFontWidth($code_police)*strlen("".$code.""))/2,0,$code,$ecriture_color);
imagejpeg($img,'',30);
imageDestroy(^$img);
?>
A voir également:

2 réponses

Bonjour,

J'ai modifié le code de la captcha qui ne fonctionnait pas :

<?php 
session_start(); 
$liste="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
$code=''; 
while(strlen($code)!=6){ 
$code.=$liste[rand(0,36)]; 
} 
$_SESSION['code']=$code; 
$img=imagecreate(70,20) or die ("Problème de création GD"); 
$background_color=imagecolorallocate($img,238,238,238); 
$ecriture_color=imagecolorallocate($img,0,0,0); 
$code_police=5; 
header('Expires: Mon, 26 Jul 1997 05h00 GMT'); 
header('Cache-Control: no-store, no-cache, must-revalidate'); 
header('Cache-Control: post-check=0, pre-check=0', false); 
header("Content-type: image/jpeg"); 
imageString($img,$code_police,(70-imageFontWidth($code_police)*strlen($code))/2,0,$code,$ecriture_color); 
imagejpeg($img,'',30); 
imageDestroy($img); 
?> 


Là c'est bon, tout fonctionne.


Cordialement

Zébulon
0
siegfrield Messages postés 4 Date d'inscription samedi 7 février 2009 Statut Membre Dernière intervention 9 septembre 2011
7 sept. 2011 à 19:48
Merci beaucoup neoprog67, t'es un crack. Ça fonctionne à merveille même si le captcha n'est pas très esthétique au final, mais ça c'est pas de ta faute !

Merci encore.
0
Utilisateur anonyme
8 sept. 2011 à 07:47
Non effectivement 8-)

De rien de bonne continuation. N'oubliez pas de marquer le thread comme résolu.
0