Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

Login and Registration Form in PHP using Mysqli

July 10, 2018 Pakainfo Programming, Mysql, Mysqli, php Leave a comment

Login and Registration Form in PHP using Mysqli

Contents

  • Login and Registration Form in PHP using Mysqli
    • Session.php
    • Login using Mysqli with PHP
    • Logout in PHP using mysqli
    • login.php
    • Related posts

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

<?php 
	error_reporting(0);
	include('includes/config.php');
	// Connect to the database
	$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
	session_start();
	$check = $_SESSION['login_username'];
	if(!isset($check)) {
	    header("Location:index.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

<?php
//your all the session_destroy here in mysqil
session_start();
session_destroy();

header("Location: index.php");
?>

login.php

<?php

include('header.php');
// simple Connect to the database display in mysqil
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);

// here output any connection error display in mysqil
if ($mysqli->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");
}
?>

<?php include('footer.php'); ?>

Free Live Chat for Any Issue

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!.

Pakainfo
Pakainfo

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Also Read This ๐Ÿ‘‰   PayPal Subscriptions(recurring payments) Payment Gateway Integration in PHP Source Code Download

Related posts:

  1. Create a Registration and Login System with PHP and MySQL
  2. registration and signin form in php and mysql with validation
  3. jQuery Ajax Secure Login Registration System in PHP and MySQL
  4. Secure Login System with PHP and MySQLi – login page in php
  5. Laravel Custom Login Registration Example Tutorial
  6. Login and Signup System using PHP MySQLi
  7. Rregistration and login form in php and mysql with validation code free download
  8. Nodejs Login and Registration with PHP MySQL and SQLite Example
Also Read This ๐Ÿ‘‰   php array to javascript array - How to Convert PHP Array to JavaScript Array?
login and registration form in php using sessionlogin and registration form in php with mysqllogin code in php using mysqlilogin form in php using mysqliphp login page code with mysqliphp mysqli login system tutorialregistration and login form in php and mysql with validationregistration and login form in php and mysql with validation code free download

Post navigation

Previous Post:PHP and MySqli CRUD Operation Tutorial
Next Post:Enable Disable settings jQuery DataTables

Search

Write For Us

Weโ€™re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (56) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (100) Codeigniter (175) CSS (98) Earn Money (61) Education (56) Entertainment (121) fullform (82) Google Adsense (62) Highcharts (77) Hollywood (101) JavaScript (1356) Jobs (40) jQuery (1422) Laravel (1087) LifeStyle (51) movierulz4 (55) Mysql (1029) Mysqli (890) Node.js (39) php (2117) Programming (2330) Python (96) ReactJS (37) Software (134) Software (83) Stories (94) tamilrockers (96) Tamilrockers kannada (56) Tamilrockers telugu (55) Tech (132) Technology (2377) Tips and Tricks (113) Tools (168) Top10 (388) Trading (69) Trending (63) VueJs (250) Web Technology (93) webtools (173) wordpress (166) World (209)

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here

  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

ยฉ 2022 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype YouTube Tag Extractor