Jump to content

User Authentication Login Problems


jedney

Recommended Posts

Hello.

 

I am having a problem making a user authentication script.  I've done about 5 scripts, and I get problems with them all, so I was wondering if anyone can help me out here, I don't want to do a new one, I need to find out what's wrong with what I have.

 

<?php

ini_set('error_reporting',E_ALL);


// Start login session
session_start();

$errorMessage = '';

// Set username and password variables
$username = $_POST['username'];
$password = $_POST['password'];

// Check database for username/password
$sql = "SELECT username
		FROM users
		WHERE username = '$username'
		AND password = MD5('$password')";
			  
$result = mysql_query($sql)
		or die('Query failed: ' . mysql_error());

if (mysql_num_rows($result) == 1) {
	// Username and Password match
	// Set session
	$_SESSION['user_logged_in'] = true;

	// Move to member page after login
	header('location: members.php');
	exit;
	} else {
		echo "     Login Faild"; echo "</td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td class=\"norm\">Your login attempt was not successfull.  If you feel you have received this message in error, please contact Lev.</td></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td></td></td></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td></td>"; }?>

 

When I login, I receive this error:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/c575964/public_html/b1/processlogin.php: in /home/c575964/public_html/b1/processlogin.php on line 77

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/c575964/public_html/b1/processlogin.php: in /home/c575964/public_html/b1/processlogin.php on line 77

 

Also, line 77 is:

session_start();

 

But alternatively to the session issue, the login fails.

Link to comment
Share on other sites

Yes, I have a lot of HTML before the script.

 

<?php include('connect.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Next Level Gaming :: A Professional Day of Defeat Gaming Team</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" class="MainTable">
  <tr>
    <td colspan="2"><img src="images/header.gif" alt="Next Level Gaming" width="800" height="100" longdesc="Next Level Gaming - A Professional Day of Defeat Team" /></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
  </tr>
  <tr>
    <td class="MainLeftCol"><table width="175" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="images/navhdr.gif" alt="Navigation" width="200" height="15" /></td>
      </tr>
      <tr>
        <td><div class="norm"><?php
             // DISPLAY NAVIGATION INFORMATION
    $query = "SELECT * FROM navigation WHERE type='1'";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)){
    $link = $row["link"] ;
    $url = $row["url"] ;
    echo "<div class=\"norm\"><a href=". $row["url"] .">". $row["link"] ."</a><br /></div>";
    }
    ?></div></td>
      </tr>
      <tr>
        <td> </td>
      </tr>
      <tr>
        <td><img src="images/dodhdr.gif" alt="Day of Defeat Resources" width="200" height="15" /></td>
      </tr>
      <tr>
        <td><span class="norm">
          <?php
             // DISPLAY NAVIGATION INFORMATION
    $query = "SELECT * FROM navigation WHERE type='2'";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)){
    $link = $row["link"] ;
    $url = $row["url"] ;
    echo "<a href=\"". $row["url"] ."\">". $row["link"] ."</a><br />";
    }
    ?>
        </span></td>
      </tr>
      <tr>
        <td> </td>
      </tr>
      <tr>
        <td><img src="images/serverhdr.gif" alt="Day of Defeat 1.3 Server" width="200" height="15" /></td>
      </tr>
      <tr>
        <td><a href="http://www.gametracker.com/server_info/8.12.19.10:27015/">
<img class="noborderimg" src="http://cache.www.gametracker.com/server_info/8.12.19.10:27015/b_160x400_T0_F-1-2-3_CFFFFFF-C5C5C5-FFFFFF-434736.png" alt="" />
</a></td>
      </tr>
    </table></td>
    <td valign="top" class="MainCol"><table width="600" border="0" cellspacing="0" cellpadding="0">
      <tr>

        <td valign="top" class="NewsHeader">

 

<?

ini_set('error_reporting',E_ALL);


// Start login session


$errorMessage = '';

// Set username and password variables
$username = $_POST['username'];
$password = $_POST['password'];

// Check database for username/password
$sql = "SELECT username
		FROM users
		WHERE username = '$username'
		AND password = MD5('$password')";
			  
$result = mysql_query($sql)
		or die('Query failed: ' . mysql_error());

if (mysql_num_rows($result) == 1) {
	// Username and Password match
	// Set session
	$_SESSION['user_logged_in'] = true;

	// Move to member page after login
	header('location: members.php');
	exit;
	} else {
		echo "     Login Faild"; echo "</td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td class=\"norm\">Your login attempt was not successfull.  If you feel you have received this message in error, please contact Lev.</td></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td></td></td></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td></td>"; }?>

 

</tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2" class="MainLeftCol"><div class="copyright">Web Design & Development by Lev | © 2008, Next Level Gaming<br />
      <br />
        <img src="images/xhtml10.gif" alt="Validated as XHTML 1.0 Strict" width="50" height="18" /><img src="images/vcss.gif" alt="Validated as Valid CSS" width="50" height="18" /><br />
    </div></td>
  </tr>
</table>
</body>
</html>
</body>
</html>

 

I removed the line 77 that said session_start(), but the login still fails.

 

 

Link to comment
Share on other sites

You have to include your connect file or how do you plan on getting the MySQL data?

Try this:

<?php
// Start login session
session_start();

// Include Connect File
require('connect.php');

ini_set('error_reporting',E_ALL);


$errorMessage = '';

// Set username and password variables
$username = $_POST['username'];
$password = $_POST['password'];

// Check database for username/password
$sql = "SELECT username
		FROM users
		WHERE username = '$username'
		AND password = MD5('$password')";
			  
$result = mysql_query($sql)
		or die('Query failed: ' . mysql_error());

if (mysql_num_rows($result) == 1) {
	// Username and Password match
	// Set session
	$_SESSION['user_logged_in'] = true;

	// Move to member page after login
	header('location: members.php');
	exit;
	} else {
		echo "     Login Faild"; echo "</td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td class=\"norm\">Your login attempt was not successfull.  If you feel you have received this message in error, please contact Lev.</td></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td></td></td></td>";
      echo "</tr>";
      echo "<tr>";
        echo "<td></td>"; 
        }
        ?>

 

Link to comment
Share on other sites

I have multiple blocks of PHP code, throughout my XHTML.  My MySQL connection information, is in another file, and is the very first line of my whole page.

 

Below that, I have 2 blocks of PHP, which read the DB to display navigation links.

 

The 4th block of PHP is the code for processing the login.  I have removed the session_start(); from my script, but I still cannot login.

Link to comment
Share on other sites

That line is line 1 on the page, before any other line of anything else.

 

I am still having an issue logging in, the script keeps replying login invalid.  I'm unsure what the problem could be.  The password field is MD5 in the table, and the username matches.

 

Any ideas?

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.