MLM(Multi Level Marketing) Website Using PHP - Binary Plan

Part 6 - Login to System

In this tutorial, we will create a login script. So that user can log in to his account. This is an important phase of the project, where a user will try to open their account. So it should be very secure because we don't want that any user can access any other user's data. So let's start the process.

  • Create a page login.php.
  • Copy and paste the below code to login.php.



login.php

<?php
session_start();
require('php-includes/connect.php');
$email = mysqli_real_escape_string($con,$_POST['email']);
$password = mysqli_real_escape_string($con,$_POST['password']);

$query = mysqli_query($con,"select * from user where email='$email' and password='$password'");
if(mysqli_num_rows($query)>0){
	$_SESSION['userid'] = $email;
	$_SESSION['id'] = session_id();
	$_SESSION['login_type'] = "user";
	
	echo '<script>alert("Login Success.");window.location.assign("home.php");</script>';
	
}
else{
	echo '<script>alert("Email id or password is worng.");window.location.assign("index.php");</script>';
}

?>                        


2596