Skip to content
  • Home
  • Blog
    • yttags
    • Youtube
  • Categories
  • Tools
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
  • JS
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us
Pakainfo

Pakainfo

Web Development & Good Online education

Authentication registration and Secure login System using php

July 6, 2018 Pakainfo Programming, Mysql, Mysqli, php Leave a comment
Rate this post

Authentication registration and Secure login System using php

Welcome on Pakainfo.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Authentication registration and Secure login System using php

In this post we will show you Best way to implement How to Create a Secure Login Script in PHP and MySQL, hear for How to Create MySQL Injection free Secure Login System in PHP with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Create a table

CREATE TABLE IF NOT EXISTS `liveemployees` (
  	`id` int(10) NOT NULL AUTO_INCREMENT,
  	`first_name` varchar(100) NOT NULL,
  	`email` varchar(100) NOT NULL,
  	`clientname` varchar(100) NOT NULL,
  	`your_secpass` varchar(100) NOT NULL,
  	PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

Db Connectivity

require_once("../config.php"); 
 	global $db;

 	$db = mysqli_connect(DBHOST, DBemployee, DBsecpass, DBNAME);
 	if(!$db){
      	 	die( "Sorry!  your There seems to be some a problem connecting db to our database.");
 	}

form_register

function form_register($first_name, $employee, $secpass, $emailId){
  	 	global $db; 
  	 	$first_name = mysqli_real_escape_string($db, $first_name);
   	 	$clientname = mysqli_real_escape_string($db, $employee);
   	 	$your_secpass = mysqli_real_escape_string($db, $secpass);
   	 	$email = mysqli_real_escape_string($db, $emailId);
  	 	$wp_hasher = new your_secpassHash(16, true);
 	 	$secpass = $wp_hasher->Hashyour_secpass( trim( $your_secpass ) );
 
  	 	$sql = "INSERT INTO liveemployees (first_name, email,your_secpass,clientname) VALUES ('".$first_name."', '".$email."', '".$secpass."', '".$clientname."') "; 
  	 	$result = mysqli_query($db, $sql);
  	 	return mysqli_insert_id($db);
 	}

login_form

function login_form($employee, $secpass){
  	global $db; 
  	$clientname = mysqli_real_escape_string($db, $employee);
   	$your_secpass = mysqli_real_escape_string($db, $secpass);
  	$sql = "SELECT id, your_secpass FROM liveemployees WHERE clientname='".$clientname."' LIMIT 1 "; 
  	$result = mysqli_query($db, $sql);
  	$id = mysqli_fetch_row($result);
 	 if($id){
  	 	$your_secpass_hashed = $id[1];
 	 	 $wp_hasher = new your_secpassHash(16, true);
 	 	 if($wp_hasher->Checkyour_secpass($your_secpass, $your_secpass_hashed)) {
  	 	 	return $id[0];
  	 	}
  	} else {
  	 	return false;
  	}
}

Logout

function logout(){
 unset($_SESSION['employee_id']);
 session_destroy(); 
 header('Location: index.php');
 exit();
}

clientname Check

function clientnameExist($employee){
   	global $db; 
  	$clientname = mysqli_real_escape_string($db, $employee);
   	$sql = "SELECT id FROM liveemployees WHERE clientname='".$clientname."' LIMIT 1 "; 
  	$result = mysqli_query($db, $sql);
  	 $id = mysqli_fetch_row($result);
   	return ($id[0] > 0);
 }
}

Registration Form

<form action="" method="post" >
 <?php if(!empty($reg_errors)) {
 echo '<div class="error">';
 foreach ($form_register_errors as $error) {
 echo '<p>'.$error.'</p>';
 }
 echo '</div>';
 } ?>
 <div class="group">
 <input type="text" name="first_name" ><p class="cust_fency"></p><p class="bar"></p>
 <label>Full name</label>
 </div>
 <div class="group">
 <input type="email" name="email" ><p class="cust_fency"></p><p class="bar"></p>
 <label>Email</label>
 </div>
 <div class="group">
 <input type="text" name="clientname" ><p class="cust_fency"></p><p class="bar"></p>
 <label>clientname</label>
 </div>
 <div class="group">
 <input type="text" name="your_secpass" ><p class="cust_fency"></p><p class="bar"></p>
 <label>your_secpass</label>
 </div>
 <input type="hidden" name="form_register" value="yes" > 
 <button type="submit" class="buttonui "> <p> form_register </p>
 <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div>
 </button>  
 <a class="buttonui " href="login_form.php?action=login_form" style="line-height:4em; text-decoration: none; padding:2%" > <p> login_form Back </p> <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div></a>
  </form>

get Details

$form_register_errors= $simple_login_form_er = array();
if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['form_register'])) {
 $fields = array(
 'first_name',
 'clientname',
 'email',
 'your_secpass'
 );
 foreach ($fields as $field) {
 if (isset($_POST[$field])) $posted[$field] = stripslashes(trim($_POST[$field])); else $posted[$field] = '';
 }
 if ($posted['first_name'] == null)
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee first_name.', 'pakainfo'));
 if ($posted['email'] == null)
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee Email.', 'pakainfo'));
 if ($posted['your_secpass'] == null)
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee your_secpass.', 'pakainfo'));
 if ($posted['clientname'] == null )
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee clientname.', 'pakainfo'));
 if(clientnameExist($posted['clientname'])){
 array_push($form_register_errors, sprintf('<b>Notice</b>: The Entered clientname Already Exist.', 'pakainfo'));
 }
 $reg_errors = array_filter($form_register_errors);
 if (empty($reg_errors)) { //Check whether simple everything entered to new create new employee.
 form_register($posted['first_name'], $posted['clientname'], $posted['your_secpass'], $posted['email']); 
 } 
}

login_form Form HTML part

<form action="" method="post" >
 <?php if(!empty($log_error) || (isset($mismatchErr) && $mismatchErr != '')) {
 echo '<div class="error">';
 foreach ($simple_login_form_er as $error) {
 echo '<p>'.$error.'</p>';
 } 
 echo $mismatchErr.'</div>';
 } ?>
 <div class="group">
 <input type="text" class="used" name="clientname" ><p class="cust_fency"></p><p class="bar"></p>
 <label>clientname</label>
 </div>
 <div class="group">
 <input type="your_secpass" name="your_secpass" ><p class="cust_fency"></p><p class="bar"></p>
 <label>your_secpass</label>
 </div>
 <input type="hidden" name="login_form" value="yes" >
 <button type="submit" class="buttonui "> <p> login_form </p>
 <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div>
 </button> 
 <a class="buttonui " href="login_form.php?action=form_register" style="line-height:4em; text-decoration: none; padding:2%" > <p> form_register </p> <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div></a>
 </form>

Free Live Chat for Any Issue

PHP part

if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['login_form'])) { 
 $clientname = stripslashes(trim($_POST['clientname']));
 $your_secpass = stripslashes(trim($_POST['your_secpass']));
 $mismatchErr = '';
 if ($your_secpass == null )
 array_push($simple_login_form_er, sprintf('<b>Notice</b>: Please enter the employee your_secpass.', 'pakainfo'));
 if ($clientname == null )
 array_push($simple_login_form_er, sprintf('<b>Notice</b>: Please enter the employee clientname.', 'pakainfo'));
 $log_error = array_filter($simple_login_form_er);
 if (empty($log_error)) { //Check whether all the everything entered to create new employee.
 $login_formn = login_form($clientname, $your_secpass);
 if($login_formn){
 $_SESSION['employee_id'] = $login_formn;
 header('Location: index.php');
 exit();
 }else {
 $mismatchErr .= sprintf('<p> <b>Notice</b>: Please simple enter Valid Credentials. </p>', 'pakainfo'); 
 }
 }
}

Example

Download

I hope you have Got How to Create a Secure Login Script in PHP and MySQL And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Read Also:  Json object check if value exists Example

Related posts:

  1. jQuery Ajax Secure Login Registration System in PHP and MySQL
  2. Secure Login Remember Me PHP Session and Cookies
  3. NodeJS Login and Registration Authentication using mysql
  4. Secure Login System with PHP and MySQLi – login page in php
  5. authentication login with username or email in laravel
  6. Create a Registration and Login System with PHP and MySQL
  7. Vue.js User Signup And Login Authentication Using PHP
  8. Nodejs Login and Registration with PHP MySQL and SQLite Example
  9. jQuery AJAX login and registration Form using PHP MySQLi
  10. How to create a Login page with PHP and MySQL
Read Also:  PHP Image Upload and Crop in jQuery Example
advanced security - php register/login systemcomplete login system php mysqlhow to create a secure login script in php and mysqlphp login system with admin featuresphp secure login frameworkphp secure login script 2019php secure login script downloadphp secure login script free

Post navigation

Previous Post:Calculate get Time difference between two dates using PHP
Next Post:Insert Update Delete using PHP and mysql for Frontaccounting – crud

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
Cricday

Categories

3movierulz (48) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (92) Codeigniter (174) CSS (96) Earn Money (61) Education (53) Entertainment (108) fullform (77) Google Adsense (62) Highcharts (77) Hollywood (93) JavaScript (1354) Jobs (39) jQuery (1421) Laravel (1083) LifeStyle (50) movierulz4 (47) Mysql (1029) Mysqli (890) Node.js (38) php (2110) Programming (2320) Python (96) ReactJS (37) Software (102) Software (77) Stories (78) tamilrockers (88) Tamilrockers kannada (48) Tamilrockers telugu (47) Tech (101) Technology (2359) Tips and Tricks (107) Tools (111) Top10 (292) Trading (49) Trending (45) VueJs (250) Web Technology (83) webtools (129) wordpress (165) World (120)

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

Web Development & Good Online education : Pakainfo by Pakainfo.
Top
Subscribe On YouTube : Download Source Code & New itsolutionstuck
We accept paid guest Posting on our Site : Guest Post Chat with Us On WhatsApp