PHP Classes

File: examples.txt

Recommend this page to a friend!
  Classes of Lucas Carlson   PHP Auth   examples.txt   Download  
File: examples.txt
Role: Example script
Content type: text/plain
Description: Examples
Class: PHP Auth
Authenticate and manage users in a directory
Author: By
Last change:
Date: 19 years ago
Size: 969 bytes
 

Contents

Class file image Download
Here are some examples that you can use in your code to make use of PHP Auth.

require_once 'Auth.class.php';
$auth = new Auth;

if ($auth->loggedIn) {
    // the user is logged in
}

$theUser = array(
    "username" => $username,
    "password" => $password,
    "url" => $url,
    "ip" => $auth->userIP
    );

$numUsers = $auth->numUsers($theUser); // returns number of user with included user info

if ($numUsers == 1){
    $auth->login($theUser);
}

$added = $auth->addUser($theUser);

if (is_array($added)){
    $problems = array();
    foreach ($added as $key => $value){
        if ($value["problem"] == "unique")
            $theProblem = "<font color=red>&laquo; already taken</font>";
        if ($value["problem"] == "required")
            $theProblem = "<font color=red>&laquo; required</font>";
        if ($value["problem"] == "not valid")
            $theProblem = "<font color=red>&laquo; not a valid username</font>";
        array_push($problems, $theProblem);
    }
} else {
    // the user was succesfully added
}

$auth->logout();