login not working at all

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
egturnkey
Forum Commoner
Posts: 34
Joined: Sun Jul 26, 2009 7:35 pm

login not working at all

Post by egturnkey »

Hello friends,

I've a problem when i try to login into admin cp of an script

take a look

the admin cp login should brings username and password from an database table

however when i try to login , it keeps showing me login popup even if the username and password was correct.


here is the code

Code: Select all

 
 
<?if ($allow_page != "1") die("Sorry, there was an error.");?><?
function showlogin() {
    header('WWW-Authenticate: Basic realm="Rapid Search Script :: Admin Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo "Invalid Request. - Please retry.";
    exit;
}
 
if (!isset($_SERVER['PHP_AUTH_USER']) OR !isset($_SERVER['PHP_AUTH_PW'])) {
showlogin();
}
 
 
$sql=mysql_query("SELECT `Value` FROM `general` WHERE `Name` = 'admin_username'") or die (mysql_error());
while($row=mysql_fetch_array($sql)) $guser = "$row[Value]";
 
$sql=mysql_query("SELECT `Value` FROM `general` WHERE `Name` = 'admin_password'") or die (mysql_error());
while($row=mysql_fetch_array($sql)) $gpass = "$row[Value]";
 
 
 
if ($guser != $_SERVER['PHP_AUTH_USER']) showlogin();
if ($gpass != $_SERVER['PHP_AUTH_PW']) showlogin();
 
$username = $_SERVER['PHP_AUTH_USER'];
?>
 
 
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: login not working at all

Post by thinsoldier »

in your 2 queries are you supposed to be giving in the variables of the username and password you entered? I just see 2 hard coded values in there
Warning: I have no idea what I'm talking about.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: login not working at all

Post by klevis miho »

Try to correct this:
$guser = "$row[Value]";
into this:
$guser = $row['Value'];

and do the same for $gpass

I am not sure but try it.
kalidG
Forum Newbie
Posts: 17
Joined: Sun Dec 27, 2009 11:04 am

Re: login not working at all

Post by kalidG »

Code: Select all

<?php
// checkLogin.php
 
session_start(); // Start a new session
require('conn.php'); // Holds all of our database connection information
 
// Get the data passed from the form
$username = $_POST['user'];
$password = $_POST['password'];
 
// Do some basic sanitizing
$username = stripslashes($username);
$password = stripslashes($password);
 
$sql = "select * from users where username = '$username' and password = '$password'";
$result = mysql_query($sql) or die ( mysql_error() );
 
$count = 0;
 
while ($line = mysql_fetch_assoc($result)) {
     $count++;
}
 
if ($count == 1) {
     $_SESSION['loggedIn'] = "true";
     header("Location: loginSuccess.php"); // This is wherever you want to redirect the user to
} else {
     $_SESSION['loggedIn'] = "false";
     header("Location: loginFailed.php"); // Wherever you want the user to go when they fail the login
}
?>
this a very simple login script
try it
Post Reply