AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP Forgot Password Recover code


<< Previous Page
PHP tutorial
Next Page >>
PHP tutorial

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

Example (this is HTML - PHP editor, change text on this window)

<?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

Example (this is HTML - PHP editor, change text on this window)
  <?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: [email protected]" . "\r\n" .
"CC: [email protected]";
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

Example (this is HTML - PHP editor, change text on this window)
<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

Example (this is HTML - PHP editor, change text on this window)

<?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: [email protected]" . "\r\n" .
"CC: [email protected]";
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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...
jQuery slideUp()...
jQuery fadeToggle...
jQuery fadeOut()...
jQuery fadeIn()...
jQuery Effects - hide () and show ()...
jQuery Events...
jQuery Attributes...
jQuery Selectors...