我正在尝试使用MVC模式进行Forgot Account系统,以便它可以正常工作
并向我发送了一封邮件,我可以在其中找到插入新
的验证码密码,但我希望视图根据参数显示新的
在URL中传递的是变量$ section但是有一个错误
视图中的未定义变量$部分。
User_Controller.php
public function deconnexion()
{
//var_dump('test');die;
$client = User::Deco();
require_once('index.php');
//header('Location:http://index.php');exit;
}
user.php的
public static function RecupMDP()
{
if(isset($_GET['section']))
{
$section=htmlspecialchars($_GET['section']);
}
else
{
$section=" ";
}
if(isset($_POST['recup_submit']))
{
$recup_mail=$_POST['recup_mail'];
$db = Db::getInstance();
$mailexist =$db->prepare("SELECT id_user,login FROM users WHERE email =
?");
$mailexist->execute(array($recup_mail));
$mailexist_count = $mailexist->rowCount();
if($mailexist_count==1)
{
@session_start();
$pseudo=$mailexist->fetch();
$pseudo=$pseudo['login'];
$_SESSION['recup_mail']=$recup_mail;
$recup_code="";
for ($i=0; $i < 8; $i++)
{
$recup_code.=mt_rand(0,9);
}
//$_SESSION['recup_code']=$recup_code;
$mail_recup_exist=$db->prepare("SELECT id FROM recuperation WHERE mail=?");
$mail_recup_exist->execute(array($recup_mail));
$mail_recup_exist=$mail_recup_exist->rowCount();
if ($mail_recup_exist==1) {
$recup_insert =$db->prepare("UPDATE recuperation set code = ? WHERE mail = ?");
$recup_insert->execute(array($recup_code,$recup_mail));
}
else
{
$recup_insert =$db->prepare("INSERT INTO recuperation(mail,code) VALUES (?,?)");
$recup_insert->execute(array($recup_mail,$recup_code));
}
$header="MIME-Version: 1.0\r\n";
$header.='From:"PrimFX.com"<slim7040@hotmail.fr>'."\n";
$header.='Content-Type:text/html; charset="utf-8"'."\n";
$header.='Content-Transfer-Encoding: 8bit';
$message = '
<html>
<head>
<title>Récupération de mot de passe - PrimFX.com</title>
<meta charset="utf-8" />
</head>
<body>
<font color="#303030";>
<div align="center">
<table width="600px">
<tr>
<td>
<div align="center">Bonjour <b>'.$pseudo.'</b>,</div>
Voici votre code de récupération: <b>'.$recup_code.'</b><br/><br/>
A bientôt sur <a href="http://127.0.0.1/PROJET_WEB%20-%20Copie/">OpticDeParis.com</a> !
</td>
</tr>
<tr>
<td align="center">
<font size="2">
Ceci est un email automatique, merci de ne pas y répondre
</font>
</td>
</tr>
</table>
</div>
</font>
</body>
</html>
';
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't
have access to that
date_default_timezone_set('Etc/UTC');
require 'PHPMailer-master/PHPMailerAutoload.php';
/ /Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP
submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Username to use for SMTP authentication - use full email address for
gmail
$mail->Username = "aouadi.slim96@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "trak22683166";
//Set who the message is to be sent from
$mail->setFrom('slim.aouadi@esprit.tn', 'Aouadi Slim');
//Set an alternative reply-to address
$mail->addReplyTo('slim.aouadi@esprit.tn', 'First Last');
//Set who the message is to be sent to
$mail->addAddress($recup_mail);
//Set the subject line
$mail->Subject = 'Recuperation Mdp ';
//Read an HTML message body from an external file, convert referenced
images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->Body=$message;
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo "Message sent!";
header("Location:http://127.0.0.1/PROJET_WEB%20-%20Copie/?
controller=user&action=recupmdp§ion=code");
?>
<script type="text/javascript">
window.location.href ="?controller=user&action=recupmdp§ion=code"
</script>
<?php
}
//mail($recup_mail,"Récupération de mot de passe -
OpticDeParis.com",$message, $header);
}
else
{
echo "Cette Adresse mail n'existe pas ";
}
}
else
{
$error="Veuillez Saisir Votre Adresse Mail ! ";
}
}
}
recupmdp.php
<!-- reg-form -->
<div class="account">
<div class="account-left">
<h2>Recuperer votre mot de passe</h2>
<?php if(isset($section)=='code') { ?>
Un code de verification vous a été envoyé par mail : <?=
$_SESSION['recup_mail']?>
<br/> <br/>
<form id="registration_form" method="POST" action="?
controller=user&action=recupmdp">
<div>
<label>
<input placeholder="Code de vérification" type="text"
name="code_code">
</label>
</div>
<div>
<input type="submit" value="Valider" name="verif_submit"
id="register-submit">
</div>
<div class="forget">
</div>
</form>
<?php } elseif(isset($section)=='changemdp'){ ?>
Nouveau de mot de passe pour <?= $_SESSION['recup_mail']?>
<br/> <br/>
<form id="registration_form" method="POST" action="?
controller=user&action=recupmdp">
<div>
<label>
<input placeholder="Nouveau mot de passe" type="passeword"
name="change_mdp">
</label>
</div>
<div>
<label>
<input placeholder="Confirmation mot de passe"
type="password" name="change_mdpc">
</label>
</div>
<div>
<input type="submit" value="Recupere" name="change_submit"
id="register-submit">
</div>
<div class="forget">
</div>
</form>
<?php } else{ ?>
<div class="registration_form">
<!-- Form -->
<form id="registration_form" method="POST" action="?
controller=user&action=recupmdp">
<div>
<label>
<input placeholder="email" type="email"
name="recup_mail">
</label>
</div>
<div>
<input type="submit" value="Recupere" name="recup_submit"
id="register-submit">
</div>
<div class="forget">
</div>
</form>
<?php } ?>
<?php if(isset($error)){ echo '<span
style="color:red">'.$error.'</span>';} else {echo "<br/>";} ?>
<!-- /Form -->
</div>
</div>
<div class="clearfix"> </div>
</div>
</div>