Login and Registration Form in PHP using Mysqli
Today, We want to share with you Login and Registration Form in PHP using Mysqli.
In this post we will show you Login and Registration Form in PHP using Mysqli, hear for Login and Registration Form in PHP using Mysqli we will give you demo and example for implement.
In this post, we will learn about Login and Registration Form in PHP using Mysqli with an example.
Session.php
Login and Registration Form in PHP using Mysqli
Login using Mysqli with PHP
// Login to system if($action == 'login') { // output any connection error display in mysqil if ($mysqli->connect_error) { die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); } session_start(); extract($_POST); $username = mysqli_real_escape_string($mysqli,$_POST['username']); $pass_encrypt = md5(mysqli_real_escape_string($mysqli,$_POST['password'])); $query = "SELECT * FROM `users` WHERE username='$username' AND `password` = '$pass_encrypt'"; $results = mysqli_query($mysqli,$query) or die (mysqli_error()); $count = mysqli_num_rows($results); if($count!="") { $row = $results->fetch_assoc(); $_SESSION['login_username'] = $row['username']; $_SESSION['userid'] = $row['id']; // processing remember me option and setting cookie with long expiry date if (isset($_POST['remember'])) { session_set_cookie_params('604800'); //one week (value in seconds) session_regenerate_id(true); } echo json_encode(array( 'status' => 'Success', 'message'=> 'Login was a success! Transfering you to the system now, hold tight!' )); } else { echo json_encode(array( 'status' => 'Error', //'message'=> 'There has been an error, please try again.' 'message' => 'Login incorrect, does not exist or simply a problem! Try again!' )); } }
Logout in PHP using mysqli
login.php
connect_error) { die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error); } session_start(); //check condition display in mysqil if($_POST['username'] != "" && $_POST['password'] != "") { extract($_POST); $username = mysqli_real_escape_string($mysqli,$_POST['username']); $pass_encrypt = mysqli_real_escape_string($mysqli,$_POST['password']); $fetch = $mysqli->query("SELECT * FROM `users` WHERE username='$username' AND `password` = '$pass_encrypt'"); $row = mysqli_fetch_array($fetch); if (password_verify($pass_encrypt, $row['passowrd'])) { $_SESSION['login_username'] = $row['username']; echo 1; } else { echo 0; } } else { header("Location:index.php"); } ?>
We hope you get an idea about Login and Registration Form in PHP using Mysqli
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.
We hope This Post can help you…….Good Luck!.