WebDev: Simple Login Tutorial Using PHP. (DB Less Version)
Hi Friends,
Today I would like to say how to create a login system using PHP, without using Databases.
We need these files:
1. index.php - Index file, where your protected content and login form is there.
2. login.php - Login Form.
3. logout.php - Script for logging out.
Code: index.phpCode: login.phpCode: index.phpNow keep all the files in the same folder... Ready to execute?
Execution
I personally recommend USB Web Server for fast food execution. Download it at #-Link-Snipped-#
Now copy the three files in the Root folder of USB Web Server and open the port #-Link-Snipped-# in your favourite browser and enjoy. I have also attached the set of files, which I used with this post. 😀
All the coding is documented. Even then if you have any queries, do shoot them out in the replies. 😀
Download the files: #-Link-Snipped-#
Today I would like to say how to create a login system using PHP, without using Databases.
We need these files:
1. index.php - Index file, where your protected content and login form is there.
2. login.php - Login Form.
3. logout.php - Script for logging out.
Code: index.php
php
session_start(); // Initiate the session
?>
"https://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Welcome
if(isset($_SESSION["logged"])) // Check if the user had logged in.
echo 'Welcome! [url=logout.php]Logout[/url].';
else // User did not log in.
echo 'Please [url=login.php]Login[/url].';
?>
php
session_start(); // Initiate the session.
$err = false; // Set an Error Flag.
if(count($_POST))
if(isset($_POST["username"], $_POST["password"])) // See if the user has entered both username and password.
if($_POST["username"]=="Admin" && $_POST["password"]=="LetMeIn") // Check for the correctness of both username and password.
{
$_SESSION["logged"] = true; // Set the session as authenticated.
header('Location: index.php'); // Redirect the user to the home page.
die(); // Stop the script.
}
else
$err = true; // Username or password is wrong! Set error flag.
else
$err = true; // User didn't provide both username and password.
else
$err = false; // User logs in for the first time.
?>
Login
if($err) echo '[b]Invalid Login! Provide all values![/b]
'; // If the error flag is set, display error message. ?>
php
session_start(); // Initiate the session
session_destroy(); // Destroy the session
header('Location: index.php'); // Redirect the user to the home page
?>
Execution
I personally recommend USB Web Server for fast food execution. Download it at #-Link-Snipped-#
Now copy the three files in the Root folder of USB Web Server and open the port #-Link-Snipped-# in your favourite browser and enjoy. I have also attached the set of files, which I used with this post. 😀
All the coding is documented. Even then if you have any queries, do shoot them out in the replies. 😀
Download the files: #-Link-Snipped-#
Replies
You are reading an archived discussion.
Related Posts
in pn junction , what s depeletion capactiance and junction capactiance
'Yantra' in the ancient Indian language of Sanskrit, means 'machine', a 'Yantrik' an inventor. Yantrix uses the power of creativity to empower your world with unique machines invented for novel...
I am facing problem in connecting to postgre database in xampp
when try to execute the following script
It is showing me an unexpected error ie undefined function pg_connect()
Here...
My classmates and I had talked about this..
can anyone tell me why the sea is salty??!😕
Volvo's usually a known name in the luxury buses in India. Volvo's entered the high-end car market in India with Volvo S60. The price is Rs. 27,00,000/- (Ex. Showroom, Delhi)....