PHP Login without DataBase
PHP Tutorial » PHP Login without DataBase
How to create a simple PHP login system without a database.
To create a simplified authentication system in PHP without a database we will guide you through a few simple steps:
Creating an HTML login form.
Store user data in an array instead of the database.
Finally, protect your files by checking the session bookmark.
Redirect the user to the login page if they are not logged in.
Design HTML form Login script
Consider the following examples of HTML simple login form.
Step 1: login.php
<form action="" method="POST" name="Login_Form">
<table width="360" border="1px" align="center" cellpadding="10px" cellspacing="1" class="Table">
<?php if(isset($msg)){?>
<tr>
<td colspan="3" align="center" valign="top"><?php echo $msg;?></td>
</tr>
<?php } ?>
<tr>
<td colspan="3" align="left"><h3>Login</h3></td>
</tr>
<tr>
<td align="right">Username</td>
<td><input name="user_name" type="text" class="Input"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input name="password" type="password" class="Input"></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="Login" class="Button"></td>
</tr>
</table>
</form>
Related subjects:
PHP Simple login script witm MySQL
What is an array
GET / POST Store Data
Array to comma separated
Tags: How to create a login page in php Without database?, How can I know my database username and password in php?, login and registration form in php without database, php simple password login, php login without database, php login system with admin features, simple login form in php without mysql database, php login form no sql
PHP script to check the login authentication
Next at the top of the login page login.php we need to write a PHP script to check the login authentication
Step 2:
<?php
// Starts the session
session_start();
// Check Login form submitted
if(isset($_POST['Submit'])){
// Define username and associated password array
$logins = array('Nick' => '123456', 'Stanley' => 'admin', 'administrator' => 'admin1234');
// Check and assign submitted user_name and password to new variable
$user_name = isset($_POST['user_name']) ? $_POST['user_name'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';// Check user_name and password existence in defined array
if (isset($logins[$user_name]) && $logins[$user_name] == $password){
// Success: Set session variables and redirect to Protected page
$_SESSION['UserData']['user_name']=$logins[$user_name];
header("location:index.php");
exit;
} else {
// Unsuccessful attempt: Set error message
$msg="<span style='color:red'>Invalid Login Details</span>";
}
}?>
<form action="" method="POST" name="Login_Form">
<table width="360" border="1px" align="center" cellpadding="10px" cellspacing="1" class="Table">
<?php if(isset($msg)){?>
<tr>
<td colspan="3" align="center" valign="top"><?php echo $msg;?></td>
</tr>
<?php } ?>
<tr>
<td colspan="3" align="left"><h3>Login</h3></td>
</tr>
<tr>
<td align="right">Username</td>
<td><input name="user_name" type="text" class="Input"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input name="password" type="password" class="Input"></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="Login" class="Button"></td>
</tr>
</table>
</form>
PHP Login without database
Step 3:
If the login is correct, then we need to redirect the page to the protected area as index.php.
So need a protected script page too.
index.php
<?php
// Starts the session
session_start();if(!isset($_SESSION['UserData']['user_name'])){
header("location:login.php");
exit;
}
?>
Congratulation!<br />
You have logged into password protected page.<br />
<a href="logout.php">Click here</a> to Logout
logout.php
<?php
// Starts the session
session_start();// Destroy started session
session_destroy();// Redirect to login page
header("location:login.php");exit;
?>
How to create a login page in php Without database?, How can I know my database username and password in php?, login and registration form in php without database, php simple password login, php login without database, php login system with admin features, simple login form in php without mysql database, php login form no sql
PHP Login without DataBase - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.