AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP Login without DataBase


<< Previous Page
PHP tutorial
Next Page >>
PHP tutorial

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

Example (this is HTML - PHP editor, change text on this window)
<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:

Example (this is HTML - PHP editor, change text on this window)

<?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

Example (this is HTML - PHP editor, change text on this window)

<?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

Example (this is HTML - PHP editor, change text on this window)

<?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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...
jQuery slideUp()...
jQuery fadeToggle...
jQuery fadeOut()...
jQuery fadeIn()...
jQuery Effects - hide () and show ()...
jQuery Events...
jQuery Attributes...
jQuery Selectors...