Salut à tous!
Pour mon tout premier message sur ce forum, je voudrais savoir comment s'y prendre pour créer une confirmation visuelle, et ce non pas dans un forum phpBB, mais dans un formulaire d'envoi de courriel.
Le principe est de générer un texte. J'ai une fonction très basique sur mon blog , tu peux t'en inspirerRe!
J'ai cherché à travers le lien que tu as donné et trouvé des tutoriaux que je garde sous le coude. Mais, si je peux le faire moi-même, c'est encore mieux.
<?php
$img=imagecreate(200, 50);
$noir=imagecolorallocate($img, 0, 0, 0);
$blanc=imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $noir);
session_start();
$img_alea=$_SESSION["img_alea"];
imagechar($img, 5, 0, 0, $img_alea[0], $blanc);
imagechar($img, 5, 25, 0, $img_alea[1], $blanc);
imagechar($img, 5, 50, 0, $img_alea[2], $blanc);
imagechar($img, 5, 75, 0, $img_alea[3], $blanc);
imagechar($img, 5, 100, 0, $img_alea[4], $blanc);
imagechar($img, 5, 125, 0, $img_alea[5], $blanc);
imagechar($img, 5, 150, 0, $img_alea[6], $blanc);
imagechar($img, 5, 175, 0, $img_alea[7], $blanc);
header("Content-type: image/jpeg");
imagejpeg($img);
?>
Et voici celui de la page index.php (où doit s'afficher le formulaire):<?php
session_start();
$img_texte="";
$_SESSION["img_alea"]=$img_texte;
if (!isset($_POST["saisie"])) $saisie=""; else $saisie=$_POST["saisie"];
$caracteres="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
for($i=1; $i<=8; $i++){
$img_texte.=$caracteres[rand(0, 61)];
}
return $img_texte;
?>
<!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=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<?php
if (!isset($_POST["saisie"])){
?>
<form id="form1" name="form1" method="post" action="">
Veuillez saisir le code<br />
<img src="image.php?<?php echo SID ?>" /><br />
<input name="saisie" type="text" id="saisie" />
<br />
<input type="submit" name="Submit" value="OK" />
</form>
<?php
}
else{
if ($saisie==$img_texte) echo "Bravo ! vous n’êtes pas un robot.";
else echo "Réessayez, si vous n’êtes pas un robot. <a href='index.php'>Retour</a>";
}
session_unset();
session_destroy();
?>
</body>
</html>