PHP Classes
elePHPant
Icontem

File: login.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Leigh Edwards  >  PHP LDAP  >  login.php  >  Download  
File: login.php
Role: Example script
Content type: text/plain
Description: Login script example
Class: PHP LDAP
Authenticate users connecting to a LDAP server
Author: By
Last change: typo
Date: 2 years ago
Size: 1,459 bytes
 

Contents

Class file image Download
<?php

$error
= array ();

if (isset (
$_REQUEST ['function'] ) && $_REQUEST ['function'] == 'logout') {
   
$ldap->logout ();
}
if (isset (
$_POST ['username'] ) && isset ( $_POST ['password'] )) {
   
    if (empty (
$_POST ['username'] )) {
       
$error [] = 'The username needs to be set';
    }
    if (empty (
$_POST ['password'] )) {
       
$error [] = 'The password needs to be set';
    }
   
    if (
count ( $error ) == 0) {
        if (!
$ldap->login ( $_POST ['username'], $_POST ['password'] )) {
           
$error [] = 'The username and/or password are incorrect<br />';
        } else {
            if (isset (
$_SESSION ['previous_page'] )) {
               
header ( 'Location: ' . $_SESSION ['previous_page'] );
            }
        }
    }
}

?>
<h1>Login</h1>
<?php
if ($ldap->loggedIn ()) {
   
?>
Thank you, you are logged in
<br />
<br />
<a class="warning button" href="<?=$_SERVER['PHP_SELF']?>?function=logout">Logout</a>
<br />
<?php
} else {
   
   
?>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
    <div id="login">
        <label>Username:</label> <input type="text" name="username" /><br /> <label>Password:</label> <input type="password" name="password" /><br /> <br /> <input type="submit" name="submit" value="Login" />
    </div>

</form>
<?php
   
if (count ( $error ) > 0) {
       
?>
<div>
    <h4>The following errors have occured:</h4>
    <p>
        <?php
       
for($i = 0; $i < count ( $error ); $i ++) {
            echo
$error [$i] . '<br />';
        }
       
?>
</p>
</div>
<?php
   
}
}