PHP Forgot Password Recover code
PHP Tutorial » PHP Forgot Password Recover code
In this chapter we show you how to use a form to recover data, forgotten password if you forgot your username and email address.
We will send the user a password recovery email after the form is submitted.
Forgot Password Recover code step by step:
1. Connect MySQL Database with PHP Using mysqli_connect()
2. PHP Code to Send Forgotten Password by E-Mail
3. Create a Form for Forgot Password
4. Send Email Using PHP
5. Full PHP Source
Forgot Password Recover code step by step
1. Connect MySQL Database with PHP Using mysqli_connect(). Create file: database.php
2. Create a Form for Forgot Password - Created a file forgot.php into ours PHP project.
Step1: database.php
<?php
$server_name = "localhost";
$user_name = "my_username";
$password = "my_password";
$db_name = "my_DB";
// Create connection
$link = mysqli_connect($server_name,
$user_name, $password);
// Check connection
if (!$link){
die("Database Connection Failed" . mysqli_error($link));
}
$select_db = mysqli_select_db($link, $db_name);
if (!$db_name){
die("Database Selection Failed" . mysqli_error($link));
}?>
Step2: forgot.php
<?php
session_start();
include_once 'database.php';
if(isset($_POST['submit']))
{
$user_name = $_POST['user_name'];
$result = mysqli_query($conn,"SELECT * FROM Users
where user_name='" . $_POST['user_name'] . "'");
$row = mysqli_fetch_assoc($result);
$fetch_user_name=$row['user_name'];
$email_id=$row['email_id'];
$password=$row['password'];
if($user_name==$fetch_user_name) {
$to = $email_id;
$subject = "Password";
$txt = "Your password is : $password.";
$headers = "From: password_recover@agernic.com" . "\r\n" .
"CC: user_email@example.com";
mail($to,$subject,$txt,$headers);
}
else{
echo 'invalid UserName';
}
}
?>
Related subjects:
PHP Simple login script witm MySQL
login without database
GET / POST Store Data
Array to comma separated
Tags: forgot password in php code free download, code in php mysqli, using email, source cod, mysql code exemple, pdo, php forgot password send email, php code free download
Create a Form for Forgot Password
In the PHP code below, we have created one user field into the form.
The user will enter the registered user_name and then he wii receive an email once the emailid is correct.
Step 2: form-forget-pass.php
<h1>Forgot Password<h1>
<form action='method='post'>
<table cellspacing='5' align='center'>
<tr><td>UserName:</td><td><input type='text' name='user_name'/></td></tr>
<tr><td></td><td><input type='submit' name='submit' value='Submit'/></td></tr>
</table>
</form>
Full PHP code Source forget password
The full source code for recover password by email.
index.php
<?php
session_start();
include_once 'database.php';
if(isset($_POST['submit']))
{
$user_name = $_POST['user_name'];
$result = mysqli_query($conn,"SELECT * FROM Users
where user_name='" . $_POST['user_name'] . "'");
$row = mysqli_fetch_assoc($result);
$fetch_user_name=$row['user_name'];
$email_id=$row['email_id'];
$password=$row['password'];
if($user_name==$fetch_user_name) {
$to = $email_id;
$subject = "Password";
$txt = "Your password is : $password.";
$headers = "From: password_recover@agernic.com" . "\r\n" .
"CC: user_email@example.com";
mail($to,$subject,$txt,$headers);
}
else{
echo 'invalid UserName';
}
}
?><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
input{
border:1px solid green;
border-radius:2px;
}
h1{
color:darkblue;
font-size:18px;
text-align:center;
}</style>
</head>
<body><h1>Forgot Password<h1>
<form action='' method='post'>
<table cellspacing='5' align='center'>
<tr><td>UserName:</td><td><input type='text' name='user_name'/></td></tr>
<tr><td></td><td><input type='submit' name='submit' value='Submit'/></td></tr>
</table>
</form></body>
</html>
forgot password in php code free download, code in php mysqli, using email, source cod, mysql code exemple, pdo, php forgot password send email, php code free download
PHP Forgot Password Recover code - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.