OK, I understand. I'll start by the MySQL DB Layout.
Code:
TABLE:
users
FIELDS:
uid, int(4), not null, auto_increment, primary // max user limit: 9999 users
username, varchar(255), not null
password, varchar(40), not null
email, varchar(255), null // allow there to be no email attached w/ the username. change it to not null to make it required
access_lvl, int(2), not null, default (0) // 0: unprivelaged, max level:99
With the table setup as above for the user setup, we can then get on w/ the rest of it.
a couple of examples are:
PHP Code:
<?php
//==============================
// Script By: James Burke (xPlozion)
// Website: http://www.ccheater.uni.cc
// File: ~/public_html/login.php
//
// This script allows a user to login.
//==============================
define('INSITE', TRUE);
require './user_check.php';
if (!defined('LOGGED_IN')) {
if (isset($_POST['login'])) {
if (!empty($username) && !empty($password)) {
$username = mysql_real_escape_string($_POST['username']);
$password = sha1($_POST['password']);
$result = mysql_query('SELECT uid FROM users WHERE username=\''.$username.'\' AND password=\''.$password.'\' LIMIT 1');
if (mysql_num_rows($result) !== 0) {
list($uid) = mysql_fetch_row($result);
setcookie('uid', $uid, time()+3600, '/');
setcookie('password', sha1('logged_in'.$password), time()+3600, '/'); // re-encrypts the password so the db password and the cookie password aren't the same
} else {
echo 'The username/password combination does not exist.<br /><br /><a href=\'javascript:history.go(-1)\'>Go back</a>';
}
} else {
echo 'Your username or password was empty.<br /><br /><a href=\'javascript:history.go(-1)\'>Go back</a>';
}
} else {
?>
<form action='?login' method='post'>
<fieldset>
<input name='username' type='text' /> Username<br />
<input name='password' type='password' /> Password<br /><br />
<input name='login' type='submit' value='Login' />
</fieldset>
</form>
<?php
}
} else {
echo 'You are already logged in.<br /><br /><a href=\'javascript:history.go(-1)\''>Go back</a>';
}
?>
PHP Code:
<?php
//=========================
// Script By: James Burke (xPlozion)
// Website: http://www.ccheater.uni.cc
// File: ~/public_html/user_check.php
//
// This script checks to see if the user
// is logged in and sets the access level.
//
// Require this script on any page you want
// to confirm a users credentials on.
//=========================
if (!defined('INSITE'))
exit('Hacking Attempt');
// db.php is located at ~/db.php, in the root directory where
// the folder public_html is located
require '../db.php';
if(!empty($_COOKIE['uid']) && !empty($_COOKIE['password'])) {
$uid = mysql_real_escape_string($_COOKIE['uid']);
$password = $_COOKIE['password'];
$result = mysql_query('SELECT password, access_lvl FROM users WHERE uid=\''.$uid.'\' LIMIT 1');
list($db_password, $access_lvl) = mysql_fetch_row($result);
if (sha1('logged_in'.$db_password) == $password) {
define('LOGGED_IN', TRUE);
define('ACCESS_LVL', $access_lvl);
}
}
?>
That's the very basics as of right now. As far as I can tell, everything should work, so if something doesn't work, then just let me know.
Remember that +REP or donated credits is always appreciated ;)
-xP