Jump to content

Login


unidox

Recommended Posts

I have this login script:

 

include("../incs/conf.inc.php");
if ($_SESSION['admin'] == 1) {
    header("Location: index.php"); // The user is already logged in.
}

if ($_GET['s'] == 1) {
    if ($_POST['username'] == "") {
        header("Location: login.php?e=1");
    } elseif ($_POST['password'] == "") {
        header("Location: login.php?e=2");
    } else {
        // Vars
        $password = md5($_POST['password']); // Encrypts the password.
        $username = escape_data($_POST['username']);
        $admin = $level['admin'];

        //MySQL Query
        $q = mysql_query("SELECT * FROM `pcp_users` WHERE password = '$password' && username = '$username' && level <= '$admin'");
        $r = mysql_fetch_array($q);

        if (($username == "username") || ($password == md5("password"))) {
            header("Location: login.php?e=3");
        } elseif (mysql_num_rows($q) != "") { // Makes sure the username and password match up.
            if ($r['conf'] != 1) {
                header("Location: index.php?p=login&e=6");
            } else {
                header("Location: index.php"); // Redirects to the user's home page.
            	$_SESSION['admin'] = 1; // The user us logged in.
                $_SESSION['name'] = $username; // Sets the users username.
                $_SESSION['lvl'] = $admin; // Sets the users level. So admins can set page level access.
            }
        } else {
            header("Location: login.php?e=4");
        }
    }
}

 

But everytime a user logs in with the right username/password is still goes to login.php?e=4. Whats wrong

Link to comment
Share on other sites

My guess is your query is failing because of the &&

 

Replace this:

$q = mysql_query("SELECT * FROM `pcp_users` WHERE password = '$password' && username = '$username' && level <= '$admin'");

with

$q = mysql_query("SELECT * FROM `pcp_users` WHERE password = '$password' AND username = '$username' AND level <= '$admin'");

Link to comment
Share on other sites

elseif (mysql_num_rows($q) != "")

 

could this be it? mysql_num_rows will never equal "" will it? it's always going to return 0 or 1 or some other number(hopefully 1 or 0, otherwise you'll have duplicate users).

 

try:

 

elseif (mysql_num_rows($q) == 1)

 

note: i didn't try running this script, but that stuck out as a was reading it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.