David's Free Code Snippits
Php, Html, Css, Javascript Snippits...
» Categories «
Ajax
Command
Cronjob
Css
Csv
Curl
Easysiteplugins
Expressions
Functions
Htaccess
Html
Javascript
Links
Mixed
Mysql
Notes
Other
Paypal
Php
Phparrays
Security
Sessions
Xml
Sessions (Found:
1
)
1. Login to Members Area using Sessions
1) This is the html login form on "login.php" <form method="post" action="login.php"> <i>Account Username</i><br> <input type="text" name="username" value=""><br> <i>Account Password</i><br> <input type="password" name="password" value=""><br> <input type="submit" name="login" value="Login"><br> </form> 2) This is the php code to handle the html login form <?php if($_POST['login']){ //cleanup submitted username & password $login_username = trim(strip_tags($_POST['username'])); $login_password = trim(strip_tags($_POST['password'])); //check to see if any fields are blank if($login_username != ''){ if($login_password != ''){ //this is where you check if the username & password is correct //... //if everthing is correct, set the loggedin session variables session_start(); //this has to run before any headers are sent (rendered to the browser!) $_SESSION['loginok'] = 'lOginISok'.date('Ymd'); //redirect to the members area header('Location: members_area.php'); die; }else{ echo 'Incorrect Password!'; } }else{ echo 'Incorrect Username!'; } } ?> 3) Place this php code at the top of all members area files <?php session_start(); if(isset($_SESSION['loginok']) && $_SESSION['loginok'] == 'lOginISok'.date('Ymd')){ //nothing to put here... just run as a logged in user! }else{ //not logged in header('Location: index.php'); die; } ?> 4) Do this to logout, should be within "logout.php", you can just link to this file! <?php session_start(); session_destroy(); header('Location: index.php'); die; ?>