PDA

View Full Version : Login Help



ducktape
February 14th, 2003, 03:07
this is a login script I installed and I was wondering if anyone could tell me how I could modify this so when a user logs in it will take each user to a different place kinda...

here is my test info from the db

member_id
1

username
mbennett

email
mbennett@echoterra.com

say they log in as mbennett which has a member_id of 1 i wanna redirect them to like page.php?id=1 and if it were member_id 2 then redirect them to page.php?id=2

and i have the rest covered once they go to page.php?id=1 it will call the info from the db (SELECT * FROM stuff WHERE member_id = 1) basically...lol

so all i need to know is how to change this little login script to redirect the user to their respective page.






<?php

session_start();

// database connection stuff here, get code from earlier tutorials.

require "admin/config.php";

$db = mysql_connect("$dbhost", "$dbuser", "$dbpass");
mysql_select_db("$dbname",$db);

// Do basic checking, input cannot be empty

if (empty($username) || empty($memberpass))
{
die ("Error! All fields required.!");
}

// Encrypted user submitted password, remember the password stored is encrypted by hash function
$enc_pass = md5($memberpass);

// Query the database to find matching username, password

$query = "SELECT username, memberpass from members where username='$username' and memberpass='$enc_pass' ";

$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());

if (mysql_num_rows($result) != "0") // username and pass match, authenticate user
{
session_register($username); // session register the username
setcookie ("siteuser",$username,time()+604800); // set cookie containing username
Header("Location: catalog.php");

}

else { // user is not authenticated
echo "Error! Username and password does not match or no such user.";
}

?>


Any help is greatly appreciated. I am working on a member script that ppl have been asking about and once I get this and do some other minor stuff Im gonna release it as open source to the ppl who asked for it on FWS

Cagez
February 14th, 2003, 08:06
<?php

session_start();

// database connection stuff here, get code from earlier tutorials.

require "admin/config.php";

$db = mysql_connect("$dbhost", "$dbuser", "$dbpass");
mysql_select_db("$dbname",$db);

// Do basic checking, input cannot be empty

if (empty($username) || empty($memberpass))
{
die ("Error! All fields required.!");
}

// Encrypted user submitted password, remember the password stored is encrypted by hash function
$enc_pass = md5($memberpass);

// Query the database to find matching username, password

$query = "SELECT username, memberpass from members where username='$username' and memberpass='$enc_pass' ";

$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());

if (!(mysql_num_rows($result) == 0 && mysql_num_rows($result) >1)) // username and pass match, authenticate user
{
session_register($username); // session register the username
setcookie ("siteuser",$username,time()+604800); // set cookie containing username
while($fetched = mysql_fetch_array($result))
{
Header("Location: page.php?id=".$fetched['member_id']);
}

}

else { // user is not authenticated
echo "Error! Username and password does not match or no such user.";
}

?>

That should work. You needed a way of gathering what user id it was so I added a while to fetch the array. I also added a little more testing to your authentification, there also shouldn't be more then one member with the same name.

ducktape
February 14th, 2003, 09:02
thanks ill give it a shot