[ How to make a CMS 5.2 ] Login System

Linky
Article Count: 33
Posted: 21st February 03:14am
;Quick Note, This was originally posted on DarkMindZ by mitz247

Creating the Login Form
We're going to create a form to allow the user to login using the Sentry class we created on the previous page. You can create this using any HTML editor, I include a simple one in the source files at the end. We want it to look something like:
2rnts7k.jpg
Make sure the form's action is set to the filename of the page containing it (e.g., login.php), and the method is set to post. The PHP we put on this page is simple:
PHP Code:

<?php
require_once("../includes/Sentry.php");
$sentry = new Sentry(); // Create a sentry object
// Check the user's submitted login is valid
if ($HTTP_POST_VARS['user'] != ''){
    
$sentry->checkLogin($HTTP_POST_VARS['user'],$HTTP_POST_VARS['pass'],10,'welcome.php','failed.php');
}
// Log out the user
if ($HTTP_GET_VARS['action'] == 'logout'){
    
$sentry->logout();
}
?>

And that should all work nicely. The final step is to secure a page. For the purposes of the demonstration we'll create a page called welcome.php, that just says "welcome to the admin area." We only want people in groups 1 and 2 (admin and editors) to be able to access it, so at the start of the file we put:
PHP Code:

<?php
require_once('../includes/Sentry.php');
$theSentry = new Sentry();
if (!
$theSentry->checkLogin(2) ){ header("Location: login.php"); die(); }
?>

And hey presto, your page is secure. Make sure you include that code on every page you want to protect.
Once you have these basics in place, creating a fully fledged user management system isn't far away. You can create pages to allow for the automatic signup, editing, deleting and emailing of your members. Samples of all of these functions will be included in the final part of the series, which you can find here next month.
Until next time!

Comments

Information:

No Comments.