Usage examples
Initializing the class
require_once 'access.class.php';
$user = new flexibleAccess();
For better performance if there is an already established connection to MySQL you can use something like this:
//Connection to the database
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error());
require_once 'access.class.php';
$user = new flexibleAccess($link);
If you want to use an external source of settings (recommended) you can do something like this :
<?php
$settings = array(
'dbName' => 'XXX',
'dbUser' => 'XXX',
'dbPass' => 'XXX'
);
$user = new flexibleAccess('', $settings);
Checking if user is logged in
To see if the user is already logged in you can use this:
if ($user->is_loaded())
//Display something for the user here
In addition you can check if the user is active (this is a feature that many sites use)
if ($user->is_loaded() && !$user->is_active() )
echo 'Please activate your account first';
Fetching data regarding the user account
When the phpUserClass loads a user account, it fetches all the data from the user table ($user::$dbTable). In order to get any of that information you may use the get_property() and the is() methods. Bellow is an example:
if ($user->is('customer'))//This will return true if the field `customer` has the value `1`
echo 'Hello, ' . $user->get_property('firstName');
Logging in the user
Let's say that we have a form and we have posted two variables (username, password) Here is how you can use phpUserClass in order to log in the user. Mention that there is no need for addslashes() as the script automatically checks for SQL injections.
if ( !$user->login($_POST['username'],$_POST['password']) )
echo 'Wrong username and/or password';
Adding a new user to the system
To add a new user to the system you have to use the method insertUser(). This method gets an associative array that has the form field => value. Field is the database table field.
<?php
$user->insertUser( array( 'username'=>'admin', 'password'=>'pass', 'name'=>'Aristoteles', 'active'=>0) );

