Page 1 of 1

login help

Posted: Fri Apr 22, 2005 4:46 pm
by Smackie
i was wondering if someone could help me with my login script that i made i was wondering if someone could show me how to make it where the admin can login on the same login place as players but go to admin page.. and help me make the script so people can recover there passwords using there email address they signed up with the username... here is the login scrip

Code: Select all

<?php
session_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
                {
	if (!$_POST["username"] || !$_POST["password"])
		{
		die("Please go back and Supply a username and password.");
		}

	// Create query
	$q = "SELECT * FROM `dbUsers` "
		."WHERE `username`='".$_POST["username"]."' "
		."AND `password`=PASSWORD('".$_POST["password"]."') "
		."LIMIT 1";
	// Run query
	$r = mysql_query($q);

	if ( $obj = @mysql_fetch_object($r) )
	{
		// Login O.K., create session variables
		$_SESSION["valid_id"] = $obj->id;
		$_SESSION["valid_user"] = $_POST["username"];
		$_SESSION["valid_time"] = time();

	// Redirect to member page
	Header("Location: members.php");
                 	}
	else
		{
		// Login not successful
		die("Sorry, could not log you in. Wrong login information.");
		}
	                }
                else
		{
include "colors.html";
		echo "<form action=\"?op=login\" method=\"POST\">";
		echo "Username: <input name=\"username\" size=\"15\"><br />";
		echo "Password: <input type=\"password\" name=\"password\" size=\"15\"><br />";
		echo "<input type=\"submit\" value=\"Login\">";
		echo "</form>";
		}

?>
Thank you
Smackie

Posted: Fri Apr 22, 2005 5:09 pm
by bobsta63
Mate I would use a login script and have an extra field in your users table in your database called admin for example and then use 1 = Admin 0 = Not admin, Then intergrate that into the login script. So add the if tag and then use the variable to redirect them either to the admin area or normal login section.

Posted: Fri Apr 22, 2005 5:11 pm
by Smackie
i know that much im looking for someone to help me code that into there..

Posted: Fri Apr 22, 2005 5:32 pm
by John Cartwright
do something like this

Code: Select all

1. sanitize your input data
2. run your query
3. check if any rows were returned
     a) if rows were returned
            i) Check their access level
           ii) assign them their access level via sessions
                  1) redirect them to admin page if they are admin
                  OR
                     redirect them to user page if they are normal user
     b) if no rows returned login invalid
There is no need for a dropdown menu.. just have a flag in your users row that lets us know if hes an admin or normal user and run the appropriate actions depending on his access level. I would also be running checks on their access level on restricted pages.

Posted: Fri Apr 22, 2005 5:45 pm
by Smackie
:? that is like talking in a different language on that part Jcart.. i build this login from looking at alot of different kinds of code so i know not much of php im still in the process of learning i build this login script about 4 or 5 months ago and when i get admin login on with it its im going to be making it as a login script for a Chat room...