No LJ-cut, hahaha! :D

Mar 26, 2009 13:58

Okay; i got it working. It's totally awesome.
First of all, i have a database with the following table:

tbl_auth_user user_id(pk)user_passwordhome_dir zachzpass/users/zbuhrer/ maxmpass/users/mschmidt/ rhiannonrpass/users/rbuhrer/ lindsaylpass/users/lbrown/

The login form is thus:

So that (obviously) proceeds to login.php (in that directory) where the following occurs:

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
};

mysql_select_db("mysql", $con);
$result = mysql_query("SELECT * FROM tbl_auth_user;");
$usercount = "0";
$current_uname = $_POST['username'];
$current_pword = $_POST['pass'];

to connect to the database where the above table is, afterwhich the following complicated WHILE loop occurs:

while($row = mysql_fetch_array ($result))
{

$current_user_check = $row['user_id'];
$current_pass_check = $row['user_password'];
$current_home_dir = $row['home_dir'];

if ($current_user_check != $current_uname) {
$username_status = "not good";
} elseif ($current_user_check == $current_uname) {
$username_status = "good";
}

if ($current_pass_check != $current_pword) {
$password_status = "also not good";
} elseif ($current_pass_check == $current_pword) {
$password_status = "good";
}

if ($username_status != $password_status) {
$error_message = 2;

} elseif ($username_status == $password_status) {
$error_message = 0;
break;
}
}

if ($error_message == "0") {
session_start();
header('location:' . $current_home_dir);
}

if ($error_message == "2") {
header('location:http://localhost/sandbox/?error_message=2');
}

if ($error_message == "1") { // currently no conditions for error message #1
header('location:http://localhost/sandbox/$error_message=1');
}

So for each user_id and user_password in the table in the database, it checks against the user input, if any of it matches (in turn, by row), it break;s the WHILE-loop and proceeds to header('location:' . $home_dir); which is of course, localhost/users/zbuhrer (for myself as example) which doesn't have an index at the moment. I'm thinking about using cookies, or special session ID's that are also pulled from either that particular table, or a different table within the database. Anybody else done this before? (lexyeevee and niteskunk, i'm looking at you two)

I'm open to suggestion :D
Previous post Next post
Up