Jump to content

simple athentication script


prezident

Recommended Posts

i already have the front page that calls the script, but its not letting me login, i don't see the problem i know its returning the rows from the database but i don't understand why its not letting me login and when i do get it to login messing around with the code everybody logs in as an admin, my database has, user, pass, and role inside admin, poweruser, and reg user but when i get it to log in everybody logs in as an admin, can someone please help me ? i even tried the error thing but that doesn't seem to work either

 


ini_set('display_errors', 1);
error_reporting(E_ALL);
//echo ini_set('display_errors');

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if (mysql_connect("localhost", "root", ""))
    {
        //echo 'connect';    
    }
    
else
    {
        echo 'failure';
    }

if  (mysql_select_db("athentication"))
    {
        //echo 'connect';    
    }
    
else
    {
        echo 'no connect';
    }

    $result = mysql_query("SELECT * FROM login WHERE user = '$username'");
    $rows = mysql_num_rows($result);
    $role = $rows['role'];

if ($rows != 0)
{
    if ($role == 'admin')
           {
           header('Location: admin.php');
           $_SESSION['username'] = $username;
           }
           
    elseif ($role == 'poweruser')
           {
           header('Location: poweruser.php');
           $_SESSION['username'] = $username;
           }
           
    /*elseif ($role ==' reg')
           {
            echo "WHAT UP";
            $_SESSION['username'] = $username;
           }*/
}
else
    echo "enter a valid user name";




Link to comment
https://forums.phpfreaks.com/topic/221442-simple-athentication-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.