PHP Classes

File: sac.demo.php

Recommend this page to a friend!
  Packages of Mark Davidson   Simple Authentication Class   sac.demo.php   Download  
File: sac.demo.php
Role: Example script
Content type: text/plain
Description: Demo File of simpleAuthenticationClass
Class: Simple Authentication Class
Authenticate users listed in an array
Author: By
Last change: Moved where a redirect header is placed as it was causing an error.
Date: 19 years ago
Size: 2,792 bytes
 

 

Contents

Class file image Download
<?php
##################################################################################
#
# File                : sac.demo.php - Demo File of simpleAuthenticationClass
# Class Title        : simpleAuthenticationClass 
# Class Description    : Enables users to create a simple authentication system on 
#                      there site with different levels of user access, user details 
#                      are stored in an array that can be easily modified.
# Class Notes        : This is My First Publicised Class Any Input Would be 
#                      Appreciated.
# Copyright            : 2007
# Licence            : http://www.gnu.org/copyleft/gpl.html GNU Public License
#
# Author             : Mark Davidson <design@fluxnetworks.co.uk> 
#                      <http://design.fluxnetworks.co.uk>
# Created Date         : 06/01/2007
# Last Modified        : 07/01/2007
#
##################################################################################

require_once ('sac.config.inc.php');
require_once ('sac.class.inc.php');

$sac = new sac($users);

$page = $_GET['page'];
$username = $_POST['username'];
$password = sha1($_POST['password']); //sha1 encryption has been used here this can be changed when changed, you will also need to change the passwords in the config file.

if (empty($page)) {
    echo '<div style="float: right;">';
    if (!$sac->authenticate($_COOKIE['username'], $_COOKIE['password'])) {
        echo '<a href="?page=login">Login</a><br />';
    } else {
        echo '<a href="?page=logout">Logout</a><br />';
    }
    echo '</div>';
?>
<a href="?page=userarea">User Area</a><br />
<a href="?page=adminarea">Admin Area</a><br />
<a href="?page=superadmin">Super Admin Area</a>
<?php
} elseif ($page == 'login') {
    if ($_SERVER["REQUEST_METHOD"] != "POST") {
?>
<form action="#" method="post"> 
Username: <input name="username" type="text" /><br />
Password: <input name="password" type="password" /><br />
<input name="login" type="submit" value="Login" />
</form>
<?php
    } else {
        if ($sac->login($username, $password)) {
            header ("Location: {$_SERVER['SCRIPT_NAME']}");
            echo 'Login was Successful<br />';
        } else {
            echo 'Login Failed<br />';
        }
    }
} elseif ($page == 'userarea') {
    if ($sac->authenticate($_COOKIE['username'], $_COOKIE['password'])) {
        echo 'Valid User<br />';
    } else {
        echo 'Not Valid User<br />';
    }
} elseif ($page == 'adminarea') {
    if ($sac->authenticate($_COOKIE['username'], $_COOKIE['password'], 2)) {
        echo 'Valid Admin<br />';
    } else {
        echo 'Not Valid Admin<br />';
    }
} elseif ($page == 'superadmin') {
    if ($sac->authenticate($_COOKIE['username'], $_COOKIE['password'], 3)) {
        echo 'Valid Super Admin<br />';
    } else {
        echo 'Not Valid Super Admin<br />';
    }
} elseif ($page == 'logout') {
    $sac->logout();
    header ("Location: {$_SERVER['SCRIPT_NAME']}");
}
?>