Here we are developing code of how to develop php script for forget password. this is very simple and easy script for forget password in php.
you just have need some knowledge of php, mysql and some basic php applications such as login script and user registration and some mysql queries.
Lets we Start Php Code for Forget Password Script.
First we have need to create connection file connect to database.
<?php //error_reporting(0); session_start(); ob_start(); /** The name of the database */ define('DB_NAME', 'phpkidadb'); /** MySQL database username */ define('DB_USER', 'root'); /** MySQL database password */ define('DB_PASSWORD', ''); /** MySQL hostname */ define('DB_HOST', 'localhost'); $con=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD); mysqli_select_db($con, DB_NAME); ?>
After created connection file we have need create php cript for forget password.
so here we will check form is submit or not if form is submit, then we will check enter email id by user is exist in user table of database, if email id exist so execute code of send password on email and show message to user. and if email id not exist in this case show error message to user.
PHP Code For Forget Password
<?php //error_reporting(0); if(isset($_POST['fpass'])) { $email=$_POST['email']; $pres=mysqli_query($con, "select email, password from users where email='$email'"); $count=mysqli_num_rows($pres); if($count==1) { $presfet=mysqli_fetch_assoc($pres); $pass=$presfet['password']; $to = $email; // subject $subject = ' Reset Your Password '; // message $message = ' <html> <head> <title> Forget Password Script In PHP - PHPKIDA </title> <style> h3{color:#FF0000;} </style> </head> <body> <h3>'.$pass.'</h3> </body> </html> '; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Forget Password <support@phpkida.com/>' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); echo "Your Password Sent On Your Email Id, Check and login !"; } else{echo "Email Id Does Not Match ! Please Try Again And Check Your Email Id.";} } ?>
HTML Code For Form
<form method="post"> <input name="email" type="text" placeholder="Enter Your Email Id" required> <input type="submit" value="Reset Password" name="fpass"> </form>
I Hope You Like This Tutorial. If You Have Any Question Please Leave comment we will be focus on. Thank For Visit.
My name is Mukesh Jakhar and I am a Web Application Developer and Software Developer, currently living in Jaipur, India. I have a Master of Computer Application in Computer Science from JNU Jaipur University. I loves to write on technology and programming topics. Apart from this, I love to travel and enjoy the beauty of nature.