Jump to content

Archived

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

simcoweb

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

Recommended Posts

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:

[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!";
}
}
}
?>[/code]

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!

Share this post


Link to post
Share on other sites
Script looks fine, but why did you comment out parts that need?


Try this:
[code]<?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!";
}
}
}


?>[/code]

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

Share this post


Link to post
Share on other sites
Actually the $eg_error values are displayed in the body of the HTML in this:

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

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.

Share this post


Link to post
Share on other sites
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:

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

Share this post


Link to post
Share on other sites

×

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.