1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| <?php
try {
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$cnx = new PDO('mysql:host=localhost;dbname=data', 'root', '', $pdo_options);;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
<?php
if(!empty($_POST) && strlen($_POST['prenom'])>4 && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$prenom = addslashes($_POST['prenom']);
$email = addslashes($_POST['email']);
$password = sha1($_POST['password']);
$token = sha1(uniqid(rand()));//On génére un jeton totalement unique
$q = array('prenom'=>$prenom, 'email'=>$email, 'password'=>$password, 'token'=>$token);
$sql = 'INSERT INTO users (prenom, email, password, token) VALUES (:prenom, :email, :password, :token)';
$req = $cnx->prepare($sql);
$req->execute($q);
?>
<?php
//Envoyer un mail pour la validation du compte
require_once ("fonction_passage_ligne.php");
require_once('mailer/class.phpmailer.php');
function smtpmailer($to,$subject,$body,$header){
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'contact@gmail.com';
$mail->Password = 'password';
$mail->SetFrom('contact@gmail.com', 'Admin Site');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
//=====Declaration du destinataire
$to = $email;
//=====Déclaration du message au format texte
$message_html = '
Bonjour, veuillez activer votre compte en cliquant ici ->
<a href="http://localhost/Projet Informatique/Site/activate.php?token='.$token.'&email='.$to.'">
Activation du compte</a>
';
//==========
//=====Création de la boundary
$boundary = "-----=".md5(rand());
//==========
//=====Définition du sujet.
$subject = 'Activation de votre compte';
//=====Création du header de l'e-mail
$header = "From: \"Site\"<contact@gmail.com>".$passage_ligne;
$header .= "Reply-To: contacts@gmail.com".$passage_ligne;
$header .= "MIME-Version: 1.0".$passage_ligne;
$header .= "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
//=====Création du message
$body = $passage_ligne."--".$boundary.$passage_ligne;
$body.= "Content-Type: text/plain; charset=\"ISO-8859-1\"".$passage_ligne;
$body.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
$body.= $passage_ligne.$message_html.$passage_ligne;
//==========
$body.= $passage_ligne."--".$boundary."--".$passage_ligne;
//=====Envoi de l'e-mail.
smtpmailer($to,$subject,$body,$header);
//==========
}
else{
if(!empty($_POST) && strlen($_POST['prenom'])<4){
$error_prenom = ' Votre prenom doit comporter au minimun 4 caracteres !';
}
if(!empty($_POST) && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$error_email = ' Votre Email n\'est pas valide !';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="style.css" />
<title>Site</title>
<!--[if lte IE 7]>
<link rel="stylesheet" href="style_ie.css" />
<![endif]-->
</head>
<body>
<div id="bloc_page">
<?php include('header.php');?>
<?php include('nav.php');?>
<section>
<div id="barre_recherche">
</div>
<article>
<h2>Formulaire d'inscription :</h2>
<form action="register.php" method="POST">
<label for="prenom">Prénom : </label><br/>
<input type="text" name="prenom"/><br/>
<!--S'il y a une erreur dans le prenom -->
<div class="error"><?php if(isset($error_prenom))echo $error_prenom;?></div>
<label for="email">Email : </label><br/>
<input type="text" name="email"/><br/>
<!--S'il y a une erreur dans le mail -->
<div class="error"><?php if(isset($error_email))echo $error_email;?></div>
<label for="password">Password : </label><br/>
<input type="password" name="password" value=""/><br/><br/>
<input type="submit" value="S'inscrire"/>
</form><br/>
<p><?php echo $error;?></p>
</article>
</section>
<?php include('footer.php');?>
</div>
</body>
</html> |
Partager