View previous topic :: View next topic |
Author |
Message |
etorvinen -
Joined: 02 Jan 2005 Posts: 31
|
Posted: Sun Dec 03, 2006 1:04 am Post subject: Creating an PHP Auth System |
|
|
I am tring to create a authencation file using php, the goal is to create a php file manager that supports mutiple users, and maybe I can intergrate my databases together.
Here is what I have so far:
Code: |
$host = "localhost";
$user = "sqlusername";
$pass = "sqlpassword";
$db = "database";
$table_name = 'tblUsers';
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}
mysql_select_db($db);
$query = "SELECT * FROM $table_name ORDER BY id ASC";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$id = $row[0];
$username = $row[1]; /* The username. Case sensitive. */
$password = $row[2]; /* The password. Case sensitive */
$dir = "~$username";
}
|
The code works well if you have one user added to the database, when you create a second it uses the last user you created.
ex: user1 and user2 are in database
if you type user1 it will come access denied if you use user2 it will go through.
I am trying to figure out how to let it search all user fields. _________________ ;@ |
|
Back to top |
|
|
olly86 -
Joined: 25 Apr 2003 Posts: 993 Location: Wiltshire, UK
|
Posted: Sun Dec 03, 2006 2:16 am Post subject: |
|
|
$query = "SELECT * FROM $table_name WHERE username = 'varible from user' ORDER BY id ASC";
you need to select the record matching the username that the siteuser entered on the login page. to do this you need to add a WHERE clause. (eg: WHERE username = 'varibleUsername' _________________ Olly |
|
Back to top |
|
|
|