Affichage Captcha dans formulaire suite passage PHP 4.4.9 à PHP 5.6
Posté : 27 déc. 2015, 15:38
Bonjour,
Tout d'abord je tiens à préciser que je suis novice en PHP.
Je suis chez OVH et j'ai un formulaire qui fonctionne parfaitement en PHP 4.4.9.
Après un passage en PHP 5.6, l'image code.php ligne 248 (Captcha) ne s'affiche plus.
Un grand merci par avance à tous ceux qui voudraient bien m'aider.
Voici le code du formulaire qui fonctionne bien en PHP 4.4.9.
Le Formulaire
Captcha
Config
Tout d'abord je tiens à préciser que je suis novice en PHP.
Je suis chez OVH et j'ai un formulaire qui fonctionne parfaitement en PHP 4.4.9.
Après un passage en PHP 5.6, l'image code.php ligne 248 (Captcha) ne s'affiche plus.
Un grand merci par avance à tous ceux qui voudraient bien m'aider.
Voici le code du formulaire qui fonctionne bien en PHP 4.4.9.
Le Formulaire
Code : Tout sélectionner
<?php
// start session
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Document sans nom</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<html>
<body>
<?php
// fichier de conf. (form_config.php)
if(file_exists('form_config.php'))
{
include('form_config.php');
}
else
{
die('<div id="boite">Fichier de configuration non trouvé.</div>');
}
$nom = stripslashes(htmlspecialchars($_POST['nom'], ENT_NOQUOTES));
$email = htmlspecialchars($_POST['email']);
$objet = stripslashes(htmlspecialchars($_POST['objet'], ENT_NOQUOTES));
$message = stripslashes(htmlspecialchars($_POST['message'], ENT_NOQUOTES));
$dest ='Nemo <[email protected]>'."\n";
$auto_mail = htmlspecialchars($_POST['auto_mail']);
$code = htmlspecialchars($_POST['code']);
$envoyer = htmlspecialchars($_POST['envoyer']);
function boite($message)
{
echo "<div id=\"boite\">".$message."</div>";
}
if($envoyer)
{
$message_erreur = "";
if (empty($nom) || empty($email) || empty($message) || empty($code))
{
if (empty($nom)) $message_erreur .= "Vous devez remplir le champ Nom.\\n";
if (empty($email)) $message_erreur .= "Vous devez remplir le champ Email.\\n";
if (empty($message)) $message_erreur .= "Vous devez remplir le champ Message.\\n";
if (empty($code)) $message_erreur .= "Vous devez remplir le champ Code.\\n";
boite("<script language='JavaScript'>alert('".$message_erreur."');</script>");
}
else {
$minimum_long = 2;
$long_nom = strlen($nom);
if($long_nom < $minimum_long) $message_erreur .= "La saisie du nom est trop courte.\\n";
$message_long_min = 2;
$long_msg = strlen($message);
if($long_msg < $message_long_min) $message_erreur .= "Le message est trop court.\\n";
if(!preg_match("#^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$#", $email)) $message_erreur .= "L\'adresse e-mail saisie est incorrecte.\\n";
list($partie1, $domaine) = split('@', $email, 2);
if(!checkdnsrr($domaine, 'MX')) $message_erreur .= "Le domaine de votre adresse e-mail n\'existe pas.\\n";
if($_SESSION['image'] != $code) $message_erreur .= "Le code de vérification est incorrect.\\n";
if(strlen($message_erreur) > 0) boite("<script language='JavaScript'>alert('".$message_erreur."');</script>");
else
{
mail($monmail, $objet, $message, "De ".$email." (".$nom.") | A : ".$dest." | Objet : ".$objet."");
if ($act_aut_mail == 'oui' && $auto_mail) mail($email, $objet, $message, "De ".$email." (".$nom.") | A : ".$dest." | Objet : ".$objet."");
boite("<p class=\"error\">xxxx vous remercie ! <br> Votre e-mail a été envoyé avec succès ! <a href=\"http://www.xxxxxx.com/index.php\">page d'accueil</a> dans 7 ... secondes !</p>");
echo "<meta http-equiv='refresh' content='7; url=http://www.xxxxxxx.com/index.php'>";
session_unset();
session_destroy();
}
}
}
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<table width="450" border="0" align="center" cellpadding=0 cellspacing=0>
<tr>
<td width="450" rowspan="2" valign="top" bgcolor="#ffffff"><p></p>
<table width="450" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CD9E80">
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="68" align="right"><span class="Etoile">*</span><strong></strong><span class="textegris"> Nom : </span><span class="txt-titre"> </span></td>
<td width="358" height="30" colspan="2"><input type="texte" name="nom" value="<?php echo $nom; ?>" size="35" maxlength="75" style="background:#Ffffff;color:#000000"></td>
</tr>
<tr>
<td align="right"><span class="Etoile">*</span><strong><span class="textegris"> Email : </span><span class="txt-courant2-b"> </span></strong> </td>
<td height="30" colspan="2"><input type="texte" name="email" value="<?php echo $email; ?>" size="35" maxlength=75 style="background:#ffffff;color:#000000"></td>
</tr>
<tr>
<td align="right"><span class="Etoile">*</span><strong><span class="textegris"> Objet : </span><span class="txt-courant2-b"> </span></strong> </td>
<td><input type="texte" name="objet" value="<?php echo $objet; ?>" size="35" maxlength="75" style="background:#Ffffff;color:#000000"></td>
</tr>
<tr align="center">
<td colspan="3"><span class="Style11"><br/>
<br/>
<b>
<p><span class="textegris"><span class="etoile">*</span> Message :</span><br />
<textarea name="message" cols="50" rows="8" maxlength="9000" wrap="physical" style="background:#ffffff;color:#000000;"><?php echo $message; ?></textarea>
</p>
</b> </span></td>
</tr>
<tr>
<td> </td>
<td><span class="etoile">*</span> <span class="textegris">Merci de remplir les champs</span>.
<?php
if($act_aut_mail == 'oui')
{
echo '<input type="checkbox" name="auto_mail"><span class="texte12grisg"> S\'envoyer une copie<br /></span><br />';
// echo "<span class=\"bold\">$name</span>"; echo '<span class="red">$ma_variable_a_afficher_en_rouge</span>';
}
?></td>
</tr>
<tr>
<td> </td>
<td><div align="left"><img src="code.php" /> </div></td>
</tr>
<tr>
<td> </td>
<td><div align="left"><span class="textegris"><span class="etoile">*</span> Entrez le code :</span>
<input type="text" name="code" size="5" maxlength=5 style="background:#342f2c;color:#cfc6a7;" />
</div></td>
</tr>
<tr>
<td> </td>
<td><p align="center"><br />
<input type="submit" name="envoyer" class="boutonpost" style="color:#ffffff" value="Envoyer" />
<input type="reset" name="annuler" class="boutonpost" style="color:#ffffff" value="Annuler" />
</p>
<p></p>
</table>
</table>
</form>
<p></p>
<p> </p>
</body>
</html>
Code : Tout sélectionner
<?php
// start session
session_start();
// ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnpqrstwxyz123456789
$liste = 'abcdefghkmnpqrstwxyz23456789';
$code_now = '';
// =5
while(strlen($code_now) != 5)
{
$code_now .= $liste[rand(0, 63)];
}
$_SESSION['image'] = $code_now;
header('Content-type: image/jpeg');
header('Cache-Control: no-store, no-cache, must-revalidate');
// 40, 15
$img = imageCreate(50, 20);
$bc = imageColorAllocate($img, 51, 51, 51);
$texte = imageColorAllocate($img, 254, 255, 240);
// 2, 5, 1.875,
imageString($img, '4', 5, 2.875, $code_now, $texte);
// 30
imagejpeg($img, '', 30);
imageDestroy($img);
?>Code : Tout sélectionner
<?php
// adresse e-mail
$monmail = '[email protected]';
// oui pour activer l'option de s'envoyer une copie du mail
$act_aut_mail = 'oui';
// oui pour activer le lien de retour au site
$act_retoursite = 'oui';
// URL du site
$site_url = 'http://[email protected]/';
?>
