Hey does anyone know of a login script someone has someone has wirtten that uses classes.
like the tutorial on kirupa.com
Each users properties are in a class and that class is in another class:
- PHP: Select all
class User {
private $name;
function __construct( $attribs ) {
$this->name = $attribs['name'];
}
/* name methods */
function setName( $val ) {
$this->name = $val;
return;
}
function getName() {
return $this->name;
}
}
/* Contains a group of User objects */
class UsersGroup {
private $name; // name of group
private $group = array(); // group of User objects
function __construct() {
/* Connect to DB using Settings */
$link = mysql_connect(
Settings::$DATABASE['host'],
Settings::$DATABASE['username'],
Settings::$DATABASE['password']
);
mysql_select_db ( Settings::$DATABASE['database'], $link );
/* Get table names from Settings class */
$tbl_users = Settings::$TABLES['tbl_users'];
/* Query */
$sql = "SELECT user_id AS ID,
user_name AS name
FROM $tbl_users";
$result = mysql_query( $sql ) or die(mysql_error());
/* Adds user to group with each row of data */
while( $row = mysql_fetch_array($result) ) {
$this->addUser( $row );
}
}
/*
Add a user to Group
Does simple check to see if we pass an array (like $attribs)
or if we pass an object (like a User object)
*/
function addUser( $user ) {
if( is_object( $user ) ) {
array_push( $this->group, $user );
}
if( is_array( $user ) ) {
$noob = new User( $user );
array_push( $this->group, $noob );
}
return;
}
/* Returns the group (which is an array) */
function getUsers() {
return $this->group;
}
}
/* Holds our site settings */
class Settings {
static $DATABASE = array(
// change these as needed 'database' => 'kirupa_oop', // May need to be changed 'username' => 'root', 'password' => '', 'host' => 'localhost' ); static $TABLES = array( // reference to table name => actual MySQL table name 'tbl_users' => 'users' ); }
I'd like to make a system where users properties, (like user type: normal, moderator, admin) are stored in a class, and seeing somone elses code for this should help

Thankss