We describe some stem for log in form in php:
1.Firstly you will installs XAMPP in your computer.Then connect xampp.Nextly you will going to http://localhost/phpmyadmin to create database and table "admin" in this database.After creating database you insert two value such as username and password.
You can see this screenshot:
Then you will out of localhost.
2.You will create a folder that is pasted in your htdocs where xampp will be install.
3. You create a folder include where DBconnect.php will be stored.
DBconnect.php php code will be configured by your database name. you can see this code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con){
die('Could not connect:' .mysql_error());
}
$db_selected = mysql_select_db("rancho",$con);
if(!$db_selected){
die('Database not found'.mysql_error());
}
?>
After coding you will out of this folder.
4. Now you create login.php, logout.php, index.php
5. In login.php will be coded in this format:
<?php
// log in form
session_start();
if(isset($_POST['username']) && isset($_POST['password'])){
$lowerUserName = strtolower($_POST['username']);
$username = htmlentities($lowerUserName);
$password = $_POST['password'];
$mdPassWord = md5($password);
if(!empty($username) && !empty($password)){
include('include/DBconnect.php');
$result = mysql_query("SELECT * FROM `admin` WHERE `username` = '" .mysql_real_escape_string($username)."'
AND `password`='".mysql_real_escape_string($mdPassWord)."' ");
$count = mysql_num_rows($result);
if($count == 1){
$_SESSION['username'] = $username;
header('Location: index.php');
}
else{
echo "User name and pass word not found!";
}
}
else{
echo "You should fill all field";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Rootitech is stand for all</title>
</head>
<body>
<body class="profile-login">
<section class="login">
<form id="login-form" accept-charset="utf-8" method="post" action="">
<input type="text" value="" placeholder="Email or Username" tabindex="20" name="username">
<div class="password-container">
<input type="password" placeholder="Password" tabindex="21" name="password">
<span>
(
<a href="">forgot?</a>
)
</span>
</div>
<button class="button submit" data-analytics="sign-in" type="submit">Log in here</button>
<span class="create-account">
<a data-analytics="create-account" href="#">Create an Account</a>
</span>
</section>
</body>
</html>
6. After create login page you create index.php .Code will be in this format:
<?php
session_start();
if (!isset($_SESSION['username'])){
header('location: login.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Rootitech is stand for all</title>
<!-- Morris Charts CSS -->
<link href="style.css" rel="stylesheet">
</head>
<body>
<p> Rootitech is stand for all</p>
<a href="logout.php">Logout</a>
</body>
</html>
7. Now you create log out.php:
Code will be in this format:
<?php
session_start();
session_destroy();
header("Location: login.php");
?>
Finally you can get complete login form.You can style your own design.
1.Firstly you will installs XAMPP in your computer.Then connect xampp.Nextly you will going to http://localhost/phpmyadmin to create database and table "admin" in this database.After creating database you insert two value such as username and password.
You can see this screenshot:
Then you will out of localhost.
2.You will create a folder that is pasted in your htdocs where xampp will be install.
3. You create a folder include where DBconnect.php will be stored.
DBconnect.php php code will be configured by your database name. you can see this code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con){
die('Could not connect:' .mysql_error());
}
$db_selected = mysql_select_db("rancho",$con);
if(!$db_selected){
die('Database not found'.mysql_error());
}
?>
After coding you will out of this folder.
4. Now you create login.php, logout.php, index.php
5. In login.php will be coded in this format:
<?php
// log in form
session_start();
if(isset($_POST['username']) && isset($_POST['password'])){
$lowerUserName = strtolower($_POST['username']);
$username = htmlentities($lowerUserName);
$password = $_POST['password'];
$mdPassWord = md5($password);
if(!empty($username) && !empty($password)){
include('include/DBconnect.php');
$result = mysql_query("SELECT * FROM `admin` WHERE `username` = '" .mysql_real_escape_string($username)."'
AND `password`='".mysql_real_escape_string($mdPassWord)."' ");
$count = mysql_num_rows($result);
if($count == 1){
$_SESSION['username'] = $username;
header('Location: index.php');
}
else{
echo "User name and pass word not found!";
}
}
else{
echo "You should fill all field";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Rootitech is stand for all</title>
</head>
<body>
<body class="profile-login">
<section class="login">
<form id="login-form" accept-charset="utf-8" method="post" action="">
<input type="text" value="" placeholder="Email or Username" tabindex="20" name="username">
<div class="password-container">
<input type="password" placeholder="Password" tabindex="21" name="password">
<span>
(
<a href="">forgot?</a>
)
</span>
</div>
<button class="button submit" data-analytics="sign-in" type="submit">Log in here</button>
<span class="create-account">
<a data-analytics="create-account" href="#">Create an Account</a>
</span>
</section>
</body>
</html>
6. After create login page you create index.php .Code will be in this format:
<?php
session_start();
if (!isset($_SESSION['username'])){
header('location: login.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Rootitech is stand for all</title>
<!-- Morris Charts CSS -->
<link href="style.css" rel="stylesheet">
</head>
<body>
<p> Rootitech is stand for all</p>
<a href="logout.php">Logout</a>
</body>
</html>
7. Now you create log out.php:
Code will be in this format:
<?php
session_start();
session_destroy();
header("Location: login.php");
?>
Finally you can get complete login form.You can style your own design.
No comments:
Post a Comment