index.php
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>xxx</title>
<!-- Stylesheet -->
<link rel="stylesheet" type="text/css" href="xxx" />
<!-- Javascript codes -->
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/jquery.fullscreenr.js" type="text/javascript"></script>
<script type="text/javascript">
var FullscreenrOptions = { width: 1920, height: 1080, bgID: '#bgimg' };
jQuery.fn.fullscreenr(FullscreenrOptions);
</script>
</head>
<body>
<img id="bgimg" src="xxx"></img>
<div id="realBody">
<div id="container">
<h1>DARKLOTUS GAMES</h1>
<?php
echo '<br><br><br><br><font color=white>';
$file = file_get_contents('xxx', true);
$content = nl2br($file);
echo $content;
echo '</font>';
?>
</div>
<div id="sidebar">
<?php
include 'user.inc.php';
global $database;
global $username;
if(empty($_SESSION['user']))
{
if (isset ($_POST['submit']))
{
$canLogin = $user -> login ($_POST);
if (!$canLogin)
{
$user->form('login');
echo '<h3>';
$user->display_notice('login');
echo '</h3>';
echo '</form></div></div>';
}
else if ($canLogin)
{
$query = "
SELECT
username
FROM users
WHERE
username = :username
";
$queryParams = array (
':username' => $_POST['username']
);
try
{
$statement = $database -> prepare ($query);
$statement -> execute ($queryParams);
}
catch (PDOException $ex)
{
echo $ex -> getMessage ();
return false;
}
$row = $statement->fetch();
if ($row)
{
$username = $row['username'];
}
echo '<h1>Welcome, '.$username.'</h1><br>';
echo'<br>';
echo '<a href="user_cp.php"><img src="xxx" border="0" alt="Control Panel">Control Panel</a>';
echo ' ';
echo '<a href="user_cp.php?action=logout"><img src="xxx" border="0" alt="Logout">Logout</a>';
echo '</div></div>';
$user->redirect('index',0);
}
}
else
{
$user->form('login');
}
}
else if (!empty($_SESSION['user']))
{
$query = "
SELECT
username
FROM users
WHERE
username = :username
";
$queryParams = array (
':username' => $_POST['username']
);
try
{
$statement = $database -> prepare ($query);
$statement -> execute ($queryParams);
}
catch (PDOException $ex)
{
echo $ex -> getMessage ();
return false;
}
$row = $statement->fetch();
if ($row)
{
$username = $row['username'];
}
echo '<h1>Welcome, '.$username.'</h1><br>';
echo'<br>';
echo '<a href="user_cp.php"><img src="xxx" border="0" alt="Control Panel">Control Panel</a>';
echo ' ';
echo '<a href="user_cp.php?action=logout"><img src="xxx" border="0" alt="Logout">Logout</a>';
echo '</div></div>';
}
?>
</div>
</div>
</body>
</html>
user.class.php
<?php
class User
{
public $noticeCode;
private $loginData;
private $registerData;
private $statement;
public function set_array ($member, $element, $value)
{
switch ($member)
{
case 'loginData':
{
if (property_exists ($this, 'loginData'))
{
$this -> loginData[$element] = $value;
}
else
{
echo "<br> Member does not exist";
}
break;
}
case 'registerData':
{
if (property_exists ($this, 'registerData'))
{
$this -> registerData[$element] = $value;
}
else
{
echo "<br> Member does not exist";
}
break;
}
}
}
public function get_array ($member, $element)
{
switch ($member)
{
case 'loginData':
{
if (isset ($this -> loginData[$element]))
{
return $this -> loginData[$element];
}
else
{
return NULL;
}
break;
}
case 'registerData':
{
if (isset ($this -> registerData[$element]))
{
return $this -> registerData[$element];
}
else
{
return NULL;
}
break;
}
}
}
public function __construct ()
{
/* Prevent Javascript from readng SESSION cookies */
ini_set ('session.cookie_httponly', true);
/* Check if last session is from the same pc */
if (!isset ($_SESSION['last_ip']))
{
$_SESSION['last_ip'] = $_SERVER['REMOTE_ADDR'];
}
if ($_SESSION['last_ip'] !== $_SERVER['REMOTE_ADDR'])
{
/* Clear the SESSION */
$_SESSION = array ();
/* Destroy the SESSION */
session_unset ();
session_destroy ();
}
require_once("user.inc.php");
//Initialize member variables
$this->noticeCode = array();
$this->loginData = array();
$this->registerData = array();
}
public function form($action)
{
global $username;
switch($action)
{
case 'login':
{
echo '<h1>LOGIN</h1><br>';
echo '<form name="login" action="index.php" method="post">';
echo 'Username: <input type="text" name="username" /><br>';
echo 'Password: <input type="password" name="password" /><br>';
echo '<input type="submit" name = "submit" value="Login" />';
break;
}
case 'register':
{
echo '<img id="bgimg" src="xxx"></img>';
echo '<div id="realBody">';
echo '<div id="register">';
echo '<h1>REGISTER</h1><br>';
echo '<form name="register" action="user_cp.php?action=register" method="post">';
echo 'Username: <input type="text" name="username" value="xxx" /><br>';
echo 'Password: <input type="password" name="password" value="xxx" /><br>';
echo 'Verify Password: <input type="password" name="password2" value="xxx" /><br>';
echo 'E-mail: <input type="text" name="email" value="xxx" /><br>';
echo 'Verify E-mail: <input type="text" name="email2" value="xxx" /><br>';
echo '<input type="submit" name = "submit" value="Register" />';
break;
}
case 'registered':
{
echo '<img id="bgimg" src="xxx"></img>';
echo '<div id="realBody">';
echo '<div id="logout">';
echo '<h1>REGISTERED</h1><br>';
echo '<br><br>Registration Successful!';
break;
}
case 'logout':
{
echo '<img id="bgimg" src="xxx"></img>';
echo '<div id="realBody">';
echo '<div id="logout">';
echo '<h1>LOGOUT</h1><br>';
echo '<h3>';
echo '<br><br>Logout Successful!';
echo '</h3>';
break;
}
}
}
public function display_notice($action)
{
echo "<h3>";
if ($action != 'manual')
{
foreach ($this -> noticeCode as $element => $value)
{
if (!empty ($value))
{
switch($action)
{
case 'login': new Message($value); break;
case 'register': new Message($value); break;
}
}
}
}
else if ($action == 'manual')
{
new Message ($this->noticeCode['manual']);
}
echo '</h3>';
}
public function redirect($action, $wait)
{
switch($action)
{
case 'login': echo '<meta http-equiv="refresh" content="'.$wait.';url=index.php?action='.$action.'">'; break;
case 'user_cp': echo '<meta http-equiv="refresh" content="'.$wait.';url=user_cp.php">'; break;
case 'index': echo '<meta http-equiv="refresh" content="'.$wait.';url=index.php">'; break;
case 'register': echo '<meta http-equiv="refresh" content="'.$wait.';url=user_cp.php?action='.$action.'">'; break;
case 'logout': echo '<meta http-equiv="refresh" content="'.$wait.';url=user_cp.php?action='.$action.'">'; break;
}
}
public function user_cp()
{
echo '<body>';
echo '<img id="bgimg" src="xxx"></img>';
echo '<div id="realBody">';
echo '<div id="user-cp">';
echo '<h1>Control Panel</h1><br>';
echo '<a href="index.php"><img src="xxx" border="0" alt="Home">Home</a>';
echo ' ';
echo '<a href="user_cp.php?action=logout"><img src="xxx" border="0" alt="Logout">Logout</a>';
echo '</div></div>';
}
private function salt()
{
$this->loginData['salt'] = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
for ($round = 0; $round < 65536; $round++)
{
$this->loginData['salt'] = hash('sha512', $this->loginData['salt']);
}
}
private function hash($action)
{
switch($action)
{
case 'login':
{
for ($round = 0; $round < 65536; $round++)
{
$this->loginData['hash'] = hash('sha512', $this->loginData['password'] . $this->loginData['salt']);
}
break;
}
case 'register':
{
$this->salt();
for ($round = 0; $round < 65536; $round++)
{
$this->registerData['hash'] = hash('sha512', $this->registerData['password'] . $this->registerData['salt']);
}
break;
}
}
}
private function validate($action)
{
global $database;
switch($action)
{
case 'login':
{
$query = "
SELECT
id,
username,
password,
salt,
email
FROM users
WHERE
username = :username
";
$queryParams = array (
':username' => $this->loginData['username']
);
try
{
$this -> statement = $database -> prepare ($query);
$this -> statement -> execute ($queryParams);
}
catch (PDOException $ex)
{
echo $ex -> getMessage ();
$this -> noticeCode['login'] = LOGIN_FAILED;
return false;
}
$row = $this->statement->fetch();
if ($row)
{
return $row;
}
else
{
return false;
}
break;
}
case 'register':
{
/******************************************
* CHECK IF CREDENTIALS FOLLOW GUIDELINES *
******************************************/
//CHECK EMAIL
if(!filter_var($this->registerData['email'], FILTER_VALIDATE_EMAIL))
{
$this -> noticeCode['email'] = INV_EMAIL;
}
//CHECK USERNAME
$count = mb_strlen ($this->registerData['username'], 'UTF-8');
if (!ctype_alnum ($this->registerData['username']))
{
$this -> noticeCode['username'] = INV_USER;
}
else if ($count < 4)
{
$this -> noticeCode['username'] = SHORT_USER;
}
else if ($count > 15)
{
$this -> noticeCode['username'] = LONG_USER;
}
//CHECK PASSWORD
$count = mb_strlen ($this->registerData['password'], 'UTF-8');
if ($count < 6)
{
$this -> noticeCode['password'] = SHORT_PASS;
}
else if ($count > 30)
{
$this -> noticeCode['password'] = LONG_PASS;
}
if (!empty ($this -> noticeCode))
{
return false;
}
/****************************************************
* VERIFY USERNAME WITH DATABASE, UNIQUE USERS ONLY *
****************************************************/
$query = "
SELECT
1
FROM users
WHERE
username = :username
";
$query_params = array(
':username' => $this->registerData['username']
);
try
{
$this -> statement = $database->prepare($query);
$this -> statement->execute($query_params);
}
catch(PDOException $ex)
{
echo $ex -> getMessage ();
$this -> noticeCode['register'] = REG_FAILED;
return false;
}
$row = $this->statement->fetch();
if($row)
{
$this -> noticeCode['username'] = EXISTS_USER;
return false;
}
/**************************************************
* VERIFY EMAIL WITH DATABASE, UNIQUE EMAILS ONLY *
**************************************************/
$query = "
SELECT
1
FROM users
WHERE
email = :email
";
$query_params = array(
':email' => $this->registerData['email']
);
try
{
$this -> statement = $database->prepare($query);
$this -> statement->execute($query_params);
}
catch(PDOException $ex)
{
echo $ex -> getMessage ();
$this -> noticeCode['register'] = REG_FAILED;
return $regSuccess;
}
$row = $this->statement->fetch();
if($row)
{
$this -> noticeCode['email'] = EXIST_EMAIL;
return false;
}
if (empty ($this->noticeCode))
{
return true;
}
else
{
return false;
}
break;
}
}
}
public function login ($post)
{
global $database;
global $username;
if (!empty ($post))
{
foreach ($post as $element => $value)
{
if ($element != 'submit')
{
$this -> loginData[$element] = $value;
}
}
if (!empty ($this -> loginData['username']) && !empty ($this -> loginData['password']))
{
$loginOK = false;
$row = $this -> validate('login');
if ($row)
{
$this->loginData['salt'] = $row['salt'];
$this->hash('login');
if ($this->loginData['hash'] === $row['password'])
{
$loginOK = true;
//for displaying username after logged in
$username = $row['username'];
}
else
{
$this->noticeCode['login'] = LOGIN_FAILED;
}
}
if ($loginOK)
{
unset ($row['salt']);
unset ($row['password']);
$_SESSION['user'] = $row;
$this -> noticeCode['login'] = LOGIN_SUCCESS;
return true;
}
}
else
{
$this -> noticeCode['login'] = EMPTY_FIELD;
return false;
}
}
}
public function register ($post)
{
global $database;
$regSuccess = false;
if (!empty ($post))
{
foreach ($post as $element => $value)
{
if ($element != 'submit')
{
$this -> registerData[$element] = $value;
}
}
/**************************************
* CHECK IF PASSWORD AND EMAILS MATCH *
**************************************/
if ($this -> registerData['password'] == $this -> registerData['password2'] && $this -> registerData['email'] ==
$this -> registerData['email2'])
{
/*DETERMINES IF USER CAN REGISTER DATA ENTERED*/
$canRegister = $this-> validate('register');
/************************************************************
* INSERT DATA TO DATABASE, USING PDO STRUCTURED STATEMENTS *
************************************************************/
if ($canRegister)
{
$query = "
INSERT INTO users (
username,
password,
salt,
email
) VALUES (
:username,
:password,
:salt,
:email
)
";
/*GENERATE PASSWORD HASH AND ASSIGN VALUE TO "registerData" ARRAY*/
$this->hash('register');
$query_params = array(
':username' => $this->registerData['username'],
':password' => $this->registerData['hash'],
':salt' => $this->registerData['salt'],
':email' => $this->registerData['email']
);
try
{
$this->statement = $database->prepare($query);
$this->statement->execute($query_params);
}
catch(PDOException $ex)
{
echo $ex -> getMessage ();
$this -> noticeCode['register'] = REG_FAILED;
return $regSuccess;
}
$regSuccess = true;
$this -> noticeCode['register'] = REG_SUCCESS;
return $regSuccess;
}
else
{
return $regSuccess;
}
}
else
{
if ($this -> registerData['password'] != $this -> registerData['password2'])
{
$this -> noticeCode['password'] = MATCH_PASS;
}
if ($this -> registerData['email'] != $this -> registerData['email2'])
{
$this -> noticeCode['email'] = MATCH_EMAIL;
}
return $regSuccess;
}
}
else
{
$this -> noticeCode['register'] = EMPTY_FIELD;
return $regSuccess;
}
}
}
?>
user.inc.php
<?php
//Includes
require_once("database.class.php");
require_once("user.class.php");
require_once("message.class.php");
//Start an instance of the Database Class
$database = new Database();
$database = $database -> db_connect();
//Create an instance of the User Class
$user = new User();
$username = '';
//Because I have only php 5.3 I have the godawful magic quotes
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
function undo_magic_quotes_gpc(&$array)
{
foreach($array as &$value)
{
if(is_array($value))
{
undo_magic_quotes_gpc($value);
}
else
{
$value = stripslashes($value);
}
}
}
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
}
session_start();
?>
database.class.php
<?php
session_start();
class Database
{
private $dbConnect;
var $dbUser = "xxx";
var $dbPass = "xxx";
var $DSN = "mysql:host=xxx;dbname=xxx;charset=utf8";
var $options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
public function __construct ()
{
try
{
$this -> dbConnect = new PDO ($this -> DSN, $this -> dbUser, $this -> dbPass, $options);
}
catch (PDOException $ex)
{
die ("Failed to connect to the database: " . $ex -> getMessage ());
}
/*$this -> dbConnect -> setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this -> dbConnect -> setAttribute (PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);*/
}
public function db_connect ()
{
return $this -> dbConnect;
}
}
?>
style.css
body {
overflow:hidden; /* needed to eliminate scrollbars caused by the background image */
padding:0;margin:0; /* necesarry for the raster to fill the screen */
/*height:100%;width:100%;*/
}
#bgimg {
position:absolute;
z-index: -1;
}
#realBody {
position:absolute;
z-index: 5;
overflow:auto;
height:100%;width:100%;
background: url('xxx');
}
#container {
position: absolute;
width: 800px;
/*height: 640px;*/
margin-left: 5%;
margin-top: 2%;
padding-top: 8px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
border-radius: 15px;
background:rgba(0,0,0,.9);
font-family: 'space_age', sans-serif;
font-size: 20px;
}
#container h1 {
color:#fff;
font-family: 'space_age', sans-serif;
font-size:48px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#container form {
color:#fff;
font-family: 'space_age', sans-serif;
font-size:14px;
font-weight: normal;
padding-right: 28px;
text-decoration:none;
text-align:right;
}
#sidebar {
position: absolute;
width: 320px;
height: 215px;
margin-left: 64%;
margin-top: 2%;
padding-top: 8px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
border-radius: 15px;
background:rgba(0,0,0,.9);
}
#sidebar h1 {
color:#fff;
font-family: 'space_age', sans-serif;
font-size:28px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#sidebar h3 {
color:red;
font-family: verdana;
font-size:10px;
padding-left: 25px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#sidebar form {
color:#fff;
font-family: verdana;
font-size:14px;
font-weight: normal;
padding-right: 28px;
text-decoration:none;
text-align:right;
}
#logout {
width: 320px;
height: 215px;
margin: auto;
margin-top: 150px;
padding-top: 8px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
border-radius: 15px;
background:rgba(0,0,0,.9);
}
#logout h1 {
color:#fff;
font-family: 'space_age', sans-serif;
font-size:28px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#logout h3 {
color:red;
font-family: verdana;
font-size:10px;
padding-left: 25px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#register {
width: 400px;
height: 300px;
margin: auto;
margin-top: 150px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
border-radius: 15px;
background:rgba(0,0,0,.9);
}
#register h1 {
color:#fff;
font-family: 'space_age', sans-serif;
font-size:30px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#register h3 {
color:red;
font-family: verdana;
font-size:10px;
padding-left: 25px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#register form {
color:#fff;
font-family: verdana;
font-size:14px;
font-weight: normal;
padding-right: 32px;
text-decoration:none;
text-align:right;
}
#user-cp {
width: 800px;
height: 640px;
margin: auto;
margin-top: 40px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
border-radius: 15px;
background:rgba(0,0,0,.9);
}
#user-cp h1 {
color:#fff;
font-family: 'space_age', sans-serif;
font-size:34px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
#user-cp h3 {
color:red;
font-family: verdana;
font-size:10px;
padding-left: 25px;
font-weight: normal;
text-decoration:none;
text-align:center;
}
@font-face {
font-family: space_age;
src: url('xxx');
}
I believe I've given all relevant code; if you need more just let me know. Thanks again for all your guys' help thusfar, it is very much appreciated!
Also, I have been working on optimizing my code, but for now I'm just trying to get everything working the way it should so it's a bit of a mess, sorry for the eyesore haha.
This post has been edited by kiasta: 06 November 2012 - 11:32 AM

New Topic/Question
Reply



MultiQuote






|