“SimpleAuth” : Secure Login System

 

 


Table of Contents

  1. Installation
  2. Your First Secure Page
  3. Add User
  4. Logout
  5. Get the username
  6. Restricted access to some users
  7. Configuration

A) Installation - top

Installation is very simple, just copy the file simpleauth.php at the root of your website.

B) Your First Secure Page - top

With SimpleAuth, you can secure any web page. To do this you must:

  1. Use the ".php" extension for each secure page. (You can rename. "html" to ".php")
  2. Add the following line to the top of each page :
<?php ${(require_once('SimpleAuth.php'))}->protectme(); ?>

Warning, there should be no line breaks or no space before the code

To help you, look at this example:

Before :

After :


C) Add User - top

To configure users, you must open the file SimpleAuth.php

Then, simply edit the list of current users using the same logic

Trying to create a new login "administrator"with a new password and delete the demo accounts

You can now try connecting to your secure page


D) Logout - top

You can add a link to disconnect the user

For this is very simple, just make a link to the current page with the action "logout"

<a href="?simple_auth_action=logout">Logout</a>

If you want, you can redirect the user after logout

Redirect to the current folder (relative):

<?php
${(require_once('SimpleAuth.php'))}->protectme(array(
    'logoutPage' => './'
));
?>

Redirect to the root (absolute) :

<?php
${(require_once('SimpleAuth.php'))}->protectme(array(
    'logoutPage' => '/'
));
?>

Redirect to a specifique page (absolute) :

<?php
${(require_once('SimpleAuth.php'))}->protectme(array(
    'logoutPage' => '/client/news/'
));
?>

Redirect to an external page (absolute) :

<?php
${(require_once('SimpleAuth.php'))}->protectme(array(
    'logoutPage' => 'http://www.wixiweb.fr'
));
?>

You can also edit SimpleAuth.php to configure redirection for All pages :

// Allowed Users List
    'allowedUsers' => NULL,
    // The page will be displayed after logout
    'logoutPage' => 'http://www.wixiweb.fr'
    

E) Get the username - top

If you are in a secure page, you can display the user login

You can place this line to the place you want it to display the login of the user logged :

<?php echo $simpleAuthInstance->getLogin(); ?>

F) Restricted access to some users - top

You can allow access to a page to certain users only. Use the "allowedUsers" option

<?php
${(require_once('SimpleAuth.php'))}->protectme(array(
    'allowedUsers' => array('admin', 'client1')
));
?>

You can allow access to a page to certain groups of users only. Use the "allowedGroups" option

<?php
${(require_once('SimpleAuth.php'))}->protectme(array(
    'allowedGroups' => array('editor', 'administrator')
));
?>

G) Configuration - top

// Locale for translation
'locale' => 'EN',
// Allow user to change locale
'localeSwitcher' => true,

 

Go To Table of Contents