PHP Classes

File: demo/index.php

Recommend this page to a friend!
  Classes of Damian Stepien   Simple PHP User Authentication   demo/index.php   Download  
File: demo/index.php
Role: Example script
Content type: text/plain
Description: Example - index.php
Class: Simple PHP User Authentication
Authenticate users with records in a MySQL table
Author: By
Last change:
Date: 10 years ago
Size: 708 bytes
 

Contents

Class file image Download
<?php
include '../userauth.class.php';
$auth = new UserAuthentication();

if (
$auth->isLoggedIn()) {
   
$login = $auth->getLogin();
echo <<<HTML
<h1>Hello, $login</h1>
    <p><a href="logout.php">Click here to log out</a></p>
HTML;
// ^ If you haven't seen it before - it's called Heredoc - really useful thing

}
else {
   
if(isset(
$_GET['login']) && $_GET['login'] == 'error') {
    echo
'<p style="color:red">Incorrect login or password</p>';
}
echo <<<HTML
<form method="post" action="login.php">
        <p>Login: <input type="text" name="login"/></p>
        <p>Password: <input type="password" name="pass"/></p>
        <p><input type="submit" value="Log in"/></p>
    </form>
HTML;

}
?>