Login in php required following step. As we know that there are two types of website dynamic website and static website   we generally used login process in dynamic website. There are following steps of login page in php
  • First we make a login page in html.
  • The we create a database in phpAdmin.
  • Then through query we used to access the database.

First make an html page:

PAGE :-home.php

<form name="frm" method="POST">
    <table>
		<tr>
			<td>Login ID</td>
			<td><input type="text" name="LoginId" /></td>
		</tr>
		<tr>
			<td>Password</td>
			<td><input type="password" name="Password" /></td>
		</tr>
		<tr>
			<td><input type="checkbox" name="rememberme" />Remember me!</td>
			<td><input type="submit" value="Login" /></td>
		</tr>
	</table>
</form>

Save that page with home.php extension and the output of page when we run on browser is:-

Then we create database in phpmyadmin

The name of database is xyz in this we create a table user have values UID, LoginId, Password and Address.

Then we create a php page that get data from html form and compare it to the database the coding of page is describe below save that page with match.php.

PAGE: - match.php

<?php 
	ob_start();
	session_start();
	$a= $_POST['LoginId'];
	$b= $_POST['Password'];
	$c=$_POST['rememberme'];
	$encrypted_mypassword= $b;
	$con=mysql_connect("localhost","root","");
	
	if(!$con){
		die('Cound'.mysql_error());
	}
	
	mysql_select_db("xyz",$con);
	$result= mysql_query("select * from user where LoginId='$a' and Password='$encrypted_mypassword'");
	$row= mysql_fetch_array($result);

	if($row){
		$_SESSION['LoginId']= $a;
		if (isset($a) && isset($encrypted_mypassword)) {
			if (($a) && ($encrypted_mypassword)){
				if (isset($c)) {
					/* Set cookie to last 1 year */
					setcookie('LoginId', $a, time()+60*60*24*365);
					setcookie('Password', md5($encrypted_mypassword), time()+60*60*24*365);
				} else {
					/* Cookie expires when browser closes */
					setcookie('LoginId', $a, false);
					setcookie('Password', md5($encrypted_mypassword), false);
				}
				header('Location: next.php'); 
			} else {
				echo "Username/Password Invalid"; 
			}
		} else {
			echo "You must supply a username and password."; 
		}
	} else { 
		include("home.php"); 
	}
	mysql_close($con); 
?>

When we click on login box we reach on next.php page the codding of that page is describe below:-

PAGE:- next.php

<?php 
	ob_start();
	session_start();
	echo $_SESSION['LoginId'];
	
	if(isset($_SESSION['LoginId'])){ 
		echo "You were already logged in ".$_SESSION['LoginId'].".";
		echo "<a href="/p.php?id=.$_SESSION['LoginId'].">Click Here</a>";
	}else{
		header("location: home.php");
	} 
?>

Then we create a php page that get data from html form and compare it to the database the coding of page is describe below save that page with match.php.

PAGE: - match.php

<?php
	ob_start();
	session_start();
	$a= $_POST['LoginId'];
	$b= $_POST['Password'];
	$c=$_POST['rememberme'];
	$encrypted_mypassword= $b;
	$con=mysql_connect("localhost","root","");
	
	if(!$con){
		die('Cound'.mysql_error());
	}
	
	mysql_select_db("xyz",$con);
	$result= mysql_query("select * from user where LoginId='$a' and Password='$encrypted_mypassword'");
	$row= mysql_fetch_array($result);
	
	if($row){
		$_SESSION['LoginId']= $a;
		if (isset($a) && isset($encrypted_mypassword)) {
			if (($a) && ($encrypted_mypassword)) {
				if (isset($c)) {
					/* Set cookie to last 1 year */
					setcookie('LoginId', $a, time()+60*60*24*365);
					setcookie('Password', md5($encrypted_mypassword), time()+60*60*24*365);
				} else {
					/* Cookie expires when browser closes */
					setcookie('LoginId', $a, false);
					setcookie('Password', md5($encrypted_mypassword), false);
				}
				header('Location: next.php');
			} else {
				echo "Username/Password Invalid";
			}
		} else {
			echo "You must supply a username and password.";
		}
	} else {
		include("home.php");
	}
	
	mysql_close($con); 
?>

As we pass session value to that page and we print session value to that page so it will print session value 001. And we pass the hyperlink of another page through click here. And also pass the session value and cookies value through query string to another page i.e. p.php. as we encrypt password with md5 algorithm so it will pass its encrypted value through query string.

PAGE – p.php

<?php
	ob_start();
	session_start();
	echo "Hellow".$_COOKIE['LoginId'];
	echo "<br />";
	echo "Password=".$_COOKIE['Password'];
	echo "<br />";
	
	if(isset($_SESSION['LoginId'])){
		unset($_SESSION['LoginId']);
		echo "<a href="/home.php">Logout</a>";
	} else {
		header("location: home.php");
	}
?>

Then we create a php page that get data from html form and compare it to the database the coding of page is describe below save that page with match.php.

Here we again print session value and the query string value is show on toolbar. As:-

<a href="http://localhost/xyz/p.php?id=001.?Pwd=dc5c7986daef50c1e02ab09b442ee34f">
	<?php echo p.php?id=001.?Pwd=dc5c7986daef50c1e02ab09b442ee34f;?>
</a>

and when we click logout hyperlink the session is expired and the page will redirect on login page 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet

Which is best to Invest Money ?

Which is best to Invest Money ? Give your opinion......
No answer selected. Please try again.
Please select either existing option or enter your own, however not both.
Please select minimum 0 answer(s) and maximum 4 answer(s).
/polls/business-and-finance/6040-which-is-best-to-invest-money-.json?task=poll.vote
6040
radio
[{"id":"20841","title":"Share Market","votes":"26","type":"x","order":"0","pct":24.07,"resources":[]},{"id":"20842","title":"Mutual Fund","votes":"36","type":"x","order":"0","pct":33.33,"resources":[]},{"id":"20843","title":"Bank Fix Deposite","votes":"38","type":"x","order":"0","pct":35.19,"resources":[]},{"id":"20844","title":"Other","votes":"8","type":"x","order":"0","pct":7.41,"resources":[]}] ["#ff5b00","#4ac0f2","#b80028","#eef66c","#60bb22","#b96a9a","#62c2cc"] ["rgba(255,91,0,0.7)","rgba(74,192,242,0.7)","rgba(184,0,40,0.7)","rgba(238,246,108,0.7)","rgba(96,187,34,0.7)","rgba(185,106,154,0.7)","rgba(98,194,204,0.7)"] 350
bottom 200
No married couple wants to end up getting divorced. It is not like they have planned for it. They try to put up with their partners for as long as they
Due to our modern lifestyle, we feel that digestion related disorders are a common problem. Thus, we neither give importance to them nor seek any help
The bond of marriage brings the two people together. Initially, everything may seem okay and both of them slowly start discovering each other in the journey.
Methi Poriyal   Methi or Fenugreek is a small bitter brown seed that is  very nutritious and a healthy way to lowering blood sugar in diabetics.
Sweet Potato Balls / Chilakada Dumpa Purnalu Ingredients: Smashed Sweet Potato – 2 Cups Black Gram - 3 Cups Rice – 8 Cups Grated Jaggery -1 ½
History of cooking and baking Cooking is an art that needs dedication and more than anything interest .Over the centuries human beings have perfected
Fruits add a good nutrition to our body. Fruits are very good for the health. It can be included in our diet. It is said that fruits are rich in protein
Often while hearing the kebab it comes to our mind that kebab is especially made with lamb. Most of the people do not eat lamb in fact I also do not eat