if admin forget password, In this form admin enter his email id and verification mail is send and as the admin click on link redirects to change password form.
Step 1 forgetform.php
<?php
error_reporting(E_ALL);
include("config.php");
if (isset($_REQUEST['login_btn'])) {
//============email entered in form ============================
$email = $_REQUEST['email'];
$base_url = "http://website.org/prashant_1/p_project/welcome_.php?"; //landing page url for verification link
$activation = md5($email . time()); // encrypted email+timestamp
//=========================email with Account activation link
$message_body = "";
$to = $email;
$email_subject = 'Change Password';
$message_body .= "Hi, Click on the following link. "."\n";
$message_body .= "".$base_url . "activation=" . $activation."\n"; //landing page url with verification link
mail($to, $email_subject, $message_body) or die("Failed");
mysqli_query($con, "UPDATE admin SET activation='$activation', status='0' WHERE a_email='$email'"); //update Query to deactivated account by update status by ZERO
echo '<h1>Thank you Plase... Check your email account for verification link</h1>';
} else {
?>
<form name="emailform" class="emailform" method="POST" action="forgetform.php" onsubmit="return forget_email_check()">
<h2>Forget Password Page</h2>
<table>
<tr>
<td><label>Enter Your Email</label></td>
<td><input type="text" name="email" id="email" onchange="forget_email_check();
return false;"></td>
<td><span id="span1"></span></td>
</tr>
<tr>
<td><img id="loader" src="./img/loading.gif" style="display:none;"/></td>
<td><input type="submit" value="Submit" class="login_btn" name="login_btn"></td>
<td></td>
</tr>
</table>
</form>
Step 2 welcome_.php
<?php
error_reporting(E_ALL);
include("config.php");
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //to copy the current url which contains activation code
// echo $url;
$activation_code = substr($url, -32); //cut last 32 character(activation code) from current url
$data = mysqli_query($con, "SELECT * FROM admin WHERE activation ='$activation_code'"); //fetch all details which contain $activation_code in admin table
$res = mysqli_fetch_array($data);
if ($res['activation'] == $activation_code) { //if match the $activation_code redirect to newpassform.php which is to change password else error
mysqli_query($con, "UPDATE admin SET status='1' WHERE activation='$activation_code'"); //update status to 1 which means account is activated
header("location:newpassform.php");
} else {
echo "<h1>Try again : please enter a valid email address for activation</h1>";
}
?>
Step 1 forgetform.php
<?php
error_reporting(E_ALL);
include("config.php");
if (isset($_REQUEST['login_btn'])) {
//============email entered in form ============================
$email = $_REQUEST['email'];
$base_url = "http://website.org/prashant_1/p_project/welcome_.php?"; //landing page url for verification link
$activation = md5($email . time()); // encrypted email+timestamp
//=========================email with Account activation link
$message_body = "";
$to = $email;
$email_subject = 'Change Password';
$message_body .= "Hi, Click on the following link. "."\n";
$message_body .= "".$base_url . "activation=" . $activation."\n"; //landing page url with verification link
mail($to, $email_subject, $message_body) or die("Failed");
mysqli_query($con, "UPDATE admin SET activation='$activation', status='0' WHERE a_email='$email'"); //update Query to deactivated account by update status by ZERO
echo '<h1>Thank you Plase... Check your email account for verification link</h1>';
} else {
?>
<form name="emailform" class="emailform" method="POST" action="forgetform.php" onsubmit="return forget_email_check()">
<h2>Forget Password Page</h2>
<table>
<tr>
<td><label>Enter Your Email</label></td>
<td><input type="text" name="email" id="email" onchange="forget_email_check();
return false;"></td>
<td><span id="span1"></span></td>
</tr>
<tr>
<td><img id="loader" src="./img/loading.gif" style="display:none;"/></td>
<td><input type="submit" value="Submit" class="login_btn" name="login_btn"></td>
<td></td>
</tr>
</table>
</form>
Step 2 welcome_.php
<?php
error_reporting(E_ALL);
include("config.php");
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //to copy the current url which contains activation code
// echo $url;
$activation_code = substr($url, -32); //cut last 32 character(activation code) from current url
$data = mysqli_query($con, "SELECT * FROM admin WHERE activation ='$activation_code'"); //fetch all details which contain $activation_code in admin table
$res = mysqli_fetch_array($data);
if ($res['activation'] == $activation_code) { //if match the $activation_code redirect to newpassform.php which is to change password else error
mysqli_query($con, "UPDATE admin SET status='1' WHERE activation='$activation_code'"); //update status to 1 which means account is activated
header("location:newpassform.php");
} else {
echo "<h1>Try again : please enter a valid email address for activation</h1>";
}
?>
No comments:
Post a Comment