-
Problems
This line enable URL Rewriting . It must be enabled via the RewriteEngine directive! and if your .htaccess file is going to use rewrite rules, you should always include this line. Otherwise, you can’t be sure if its enabled or not. The string “on” is case insensitive.
Simple login php without database - Tutorial that teach you simple login php without database in simple five step
REQUIREMENT:
1) SERVER -Make Your Computer Server Now for Free 100% working-Learn to use wamp step by step
2)A little knowledge about php
Simple login php without database ,This is done in following way 1) first of all we need login interface 2) Second we will process the form data 3)Then we will set cookies with time limit 4) After setting cookies we need to start session 5) After starting session we need to assign session variable 5) And finally logout
STEP ONE - FORM HANDLING :In this step we will develop a simple login interface . For this we create form interface with following code
<form method="post" action="log.php" ><span id="errormassage">$error</span>
<h2>Log in </h2>
<label for="inputEmail" class="sr-only">Name</label>
<input type="text" id="inputEmail" name="user" placeholder="Username" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" name="pass" placeholder="Password" required>
<button name = "submit" type="submit">Log in</button>
</form>
<h2>Log in </h2>
<label for="inputEmail" class="sr-only">Name</label>
<input type="text" id="inputEmail" name="user" placeholder="Username" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" name="pass" placeholder="Password" required>
<button name = "submit" type="submit">Log in</button>
</form>
STEP TWO - SETTING COOKIES :In this step we will set cookies according to supplied data
What is a Cookie?
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.Create Cookies With PHP
A cookie is created with the setcookie() function.Syntax
setcookie(name, value, expire, path, domain, secure, httponly);
Only the name parameter is required. All other parameters are
optional.
if (isset($_POST['submit']) && isset($_POST['pass']) ){
$user = $_POST['user'];
$pass = $_POST['pass'];
SETCOOKIE( user , $user , time()+360000);
SETCOOKIE( pass , $pass , time()+360000);
header('location:log.php');
}
$user = $_POST['user'];
$pass = $_POST['pass'];
SETCOOKIE( user , $user , time()+360000);
SETCOOKIE( pass , $pass , time()+360000);
header('location:log.php');
}
STEP THREE - ALL ABOUT SESSION :In this step start session and assign session variable
A session is a way to store information (in variables) to be used across multiple pages.
Unlike a cookie, the information is not stored on the users computer.
What is a PHP Session?
When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser.
So; Session variables hold information about one single user, and are available to all pages in one application.
Tip: If you need a permanent storage, you may want to store the data in a database. |
Start a PHP Session
A session is started with the session_start() function.Session variables are set with the PHP global variable: $_SESSION.
if(isset($_COOKIE['user']))
{
session_start();
$_SESSION['user'] =$_COOKIE['user'];
$_SESSION['pass'] =$_COOKIE['pass'];
$user = $_SESSION['user'];
$pass = $_SESSION['user'];
//*checking if cookies is set and if specifying session variable *//
echo<<<here
you have been logged click to logout <br>
<a href='log.php?action=logout'>Log OUT</a>
here;
echo'<br>your user name is '.$user;
echo'<br>your password is '.$pass;
}
{
session_start();
$_SESSION['user'] =$_COOKIE['user'];
$_SESSION['pass'] =$_COOKIE['pass'];
$user = $_SESSION['user'];
$pass = $_SESSION['user'];
//*checking if cookies is set and if specifying session variable *//
echo<<<here
you have been logged click to logout <br>
<a href='log.php?action=logout'>Log OUT</a>
here;
echo'<br>your user name is '.$user;
echo'<br>your password is '.$pass;
}
STEP FOUR - SETTING COOKIES :In this step we will set cookies according to supplied data
if (isset($_POST['submit']) && isset($_POST['pass']) ){
$user = $_POST['user'];
$pass = $_POST['pass'];
SETCOOKIE( user , $user , time()+360000);
SETCOOKIE( pass , $pass , time()+360000);
header('location:log.php');
}
$user = $_POST['user'];
$pass = $_POST['pass'];
SETCOOKIE( user , $user , time()+360000);
SETCOOKIE( pass , $pass , time()+360000);
header('location:log.php');
}
STEP FIVE - And finally logging out . It is simple process in which we just time of cookies to negetive
if (isset($_GET['action']))
{
SETCOOKIE('user',$user,time()-3600);
SETCOOKIE('pass',$pass,time()-3600);
header('location:log.php');
}
DOWNLOAD SOURCE FILE
IF YOU HAVE ANY QUERY THEN FELL FREE TO POST IN COMMENT BELOW.Simple login php without database - Tutorial that teach you simple login php without database in simple five step
{
SETCOOKIE('user',$user,time()-3600);
SETCOOKIE('pass',$pass,time()-3600);
header('location:log.php');
}
No comments:
Post a Comment