<?php
/**
*By Red3v0lution
*Object-Oriented Content Management System
*PHP 5.2.9-1 && MySQL Database 5.1.32
*April 21, 2009
**/
/**
Usage:
___________________________________________________________________
|new register($username, $password, $register); |
|_________________________________________________________________|
|The users credentials will be stored in the database if the |
|username is free. |
|_________________________________________________________________|
**/
class register
{
//User variables
private $username;
private $password;
private $email;
//Storage variable
private $return;
//Class Methods
private function checkLogin()
{
if ($_SESSION['logged_in'] == 1)
{
if ($_SESSION['user_agent'] != $_SERVER['HTTP_USER_AGENT'])
{
$this->return = "You trying to hijack someone's session? This session is destroyed.";
$_SESSION = array();
session_destroy();
return 0;
}
else
{
$this->return = "You already have an account.";
return 0;
}
}
else
{
return 1;
}
}
private function clean()
{
$this->username = trim($this->username);
$this->password = md5($this->password);
$this->email = trim($this->email);
return 1;
}
private function IsUsernameFree()
{
$result = mysql_query("SELECT uid FROM users WHERE username = '$this->username' LIMIT 1;");
if ($row = mysql_fetch_assoc($result))
{
$this->return = "Sorry, but $this->username has already been taken. Please choose another one.";
return 0;
}
else
{
return 1;
}
}
private function create()
{
mysql_query("INSERT INTO users (username, password, email, access) VALUES ($this->username, $this->password, $this->email, 1);") OR die('Could not enter information into database. The administrator has been notified, so it should be working again soon.');
}
public function __construct($username, $password, $email)
{
$this->username = $username;
$this->password = $password;
$this->email = $email;
checkLogin() OR die($this->return);
require_once 'connect.php';
$this->clean() OR die('Supplied input could not be cleaned.');
if($this->IsUsernameFree())
{
$this->create();
}
else
{
die($this->return);
}
}
}
?>