Jump to content


Photo

I can NOT get this login script to work. Need HELP!


  • Please log in to reply
4 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 21 September 2006 - 07:57 PM

I have this login script which has been revamped 43,249,340 times and can not get it to log me in and send me to the 'members.php' page as instructed. All the page does after entering username/password is refresh itself. I've tweaked this so many times but can not get it to:

1) log the person in
2) transfer them to the proper page after login

Here's the code:

<?
// session_start();
// Set Session Value
// $_SESSION['loggedin'] = @$eg_Result1['username'];
// Declare loginError so a value is always available
$loginError = "";
			
// Turn on magic quotes to prevent SQL injection attacks
if(!get_magic_quotes_gpc())
	set_magic_quotes_runtime(1);
	
include 'dbconfig.php';
// Connect to database
$eg_objConn1 = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname, $eg_objConn1) or die(mysql());

// Validate users input
if(!empty($_POST))
{
	// Check username has a value
	if(empty($_POST['username'])) $eg_error['username'] = "Please enter a user name!";
	// Check password has a value
	if(empty($_POST['password'])) $eg_error['password'] = "Please enter a password!";
	// Check if any errors were returned and run relevant code
	if(empty($eg_error))
	{

//$username = $_POST['username'];
//$password = $_POST['password'];
// Get Record Set
$sql = ("SELECT * FROM `plateau_pros`  WHERE username = '$username' AND password = '$password'");
mysql_query($sql) or die(mysql_error());
$results = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($results) or die(mysql_error());

//$eg_Result1 = @mysql_fetch_array($eg_recResult1, MYSQL_ASSOC) or die ('Error in query: $eg_Result1. ' . mysql_error());
		
		if ($num_rows == 1) {
      // Enable sessions
			if (isset($_SESSION['loggedin']))
			{
			  header("Location: members.php");
			  exit;
			} else {
			  $_SESSION['logged'] = $_POST['username'];
	   // Go to page
			header("Location: members.php");
			break;
			}
		}
		else
		{
			$loginError = "Your user name and password do not match any in our database!";
		}
	}
}
?>

There are no errors produced so I have nothing to go by that would point to the problem. It must be my super-noobie coding capabilities. ALL help is appreciated!

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 21 September 2006 - 08:04 PM

Script looks fine, but why did you comment out parts that need?


Try this:
<?php

session_start();

// Declare loginError so a value is always available
$loginError = "";
			
// Turn on magic quotes to prevent SQL injection attacks
if(!get_magic_quotes_gpc())
	set_magic_quotes_runtime(1);
	
include 'dbconfig.php';
// Connect to database
$eg_objConn1 = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname, $eg_objConn1) or die(mysql());

// Validate users input
if(!empty($_POST))
{
	// Check username has a value
	if(empty($_POST['username'])) $eg_error['username'] = "Please enter a user name!";
	// Check password has a value
	if(empty($_POST['password'])) $eg_error['password'] = "Please enter a password!";
	// Check if any errors were returned and run relevant code
	if(empty($eg_error))
	{

$username = $_POST['username'];
$password = $_POST['password'];
// Get Record Set
$sql = ("SELECT * FROM `plateau_pros`  WHERE username = '$username' AND password = '$password'");
mysql_query($sql) or die(mysql_error());
$results = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($results) or die(mysql_error());
		
		if ($num_rows == 1) {
      // Enable sessions
			if (isset($_SESSION['loggedin']))
			{
			  header("Location: members.php");
			  exit;
			} else {
			  $_SESSION['logged'] = $_POST['username'];
	   // Go to page
			header("Location: members.php");
			break;
			}
		}
		else
		{
			$loginError = "Your user name and password do not match any in our database!";
		}
	}
}


?>

Orio.

PS-
You enter into the $eg_error array values but you are not echoing them. This is nothing important but you should look into that...
Think you're smarty?

(Gone until 20 to November)

#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 21 September 2006 - 08:12 PM

Actually the $eg_error values are displayed in the body of the HTML in this:

// Loop through all errors
if(!empty($eg_error))
{
?>
<ul>
<?
foreach($eg_error as $eg_message)
{
?>
<li id="validationError"><?= @$eg_message ?></li>
<?
}
?>
</ul>
<?
}
?>


That way it displays at the top of the form area where they can see it.

Many of the commented out items were left there as I was going through a process of elimination trying to determine where it was breaking down.

I'll give your code a shot real quick and re-post.

#4 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 21 September 2006 - 09:06 PM

aHA! I found the problem me thinks. Apparently it's logging in and it's going to the members.php page BUT the members.php page is directing it back to login.php due to a session setting. Now I have to figure that one out.

I found this out by creating a new login page called 'login-test.php' where I spliced in your code as posted. I entered a username/password that I know is valid and wound up back at 'login.php'. So, it must be hitting the members.php and then told to revert back. Here's the session settings from members.php:

// Enable sessions
session_start();
// Conditional statement
if(empty($_SESSION['loggedin']))
{
	// Go to page
	header("Location: login.php");
	exit;
}


#5 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 21 September 2006 - 09:49 PM

Ok, this is fixed. Thanks for the help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users