Jump to content

login script error


cfgcjm

Recommended Posts

I'm testing my log in script and it happens to not be working...big surprise...unfortunately i can't see why... Below is the code for all of my files. My login form is part of index.php, the script is login.php and mysql.php is the database login. I'm getting the following errors:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2

 

Index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//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=iso-8859-1"/>
<title>Digicon Media Group : Login</title>
<style type="text/css" media="all">
<!--
@import url(http://www.digiconmediagroup.com/market.css);
-->
	a:link {color:black;text-decoration:none;}
	a:visited {color:purple;text-decoration:none;}
	a:hover {color:#0066CC;text-decoration:underline;}
	a:active {color:#FF6600;text-decoration:underline;}

.style1 {
text-align: left;
}

</style>
</head>
<body>
    
  
    <div id="outer">
    <form method="post" action="login.php">
	<table style="width: 328px; height: 160px" cellspacing="0" cellpadding="0">
		<tr>
			<td style="width: 147px; height: 53px"></td>
			<td style="width: 164px; height: 53px"></td>
		</tr>
		<tr>
			<td style="height: 35px; width: 147px" class="login">USERNAME:</td>
			<td style="height: 35px; width: 164px" class="style1">
			  
			<input name="username" type="text" style="width: 95px" /> </td>
		</tr>
		<tr>
			<td style="height: 35px; width: 147px" class="login">PASSWORD:</td>
			<td style="height: 35px; width: 164px" class="style1">
			  
			<input name="password" type="password" style="width: 95px" /> </td>
		</tr>
		<tr>
			<td style="height: 47px; width: 147px"></td>
			<td style="height: 47px; width: 164px" valign="top" class="style1">
			  
			<input name="Submit1" type="submit" value="submit" /> </td>
		</tr>
	</table>
</form>
    </div>
  
  
  </body></html>

 

login.php

<?php
session_start();
require ('mysql.php');

if (isset ($_POST['submit'])) { 
$username = $_POST['username'];
$password = md5 ($_POST['password']); 
									  

// See if the user exists
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
if ($r = mysql_query ($sql)) {
	$row = mysql_fetch_array ($r);
	$num = mysql_num_rows ($r);

	if ($num > 0) { 
		$_SESSION['users_id'] = $row['users_id'];
		$_SESSION['username'] = $row['username'];
		$_SESSION['loggedin'] = TRUE;
		header("Location:yes.php");
		exit;

	} else {
		// User does not exist

		header("location:no.php");
		exit;
	}
} else {
	// The query failed
	print 'Error:' . mysql_error(); // print the MySQL error
}
}
?>

 

mysql.php

<?php
/* Connect To MySQL */

$host   = 'localhost';
$dbuser = 'XXXXX'; //
$dbpass = 'XXXXX'; //
$dbname = 'digiconm_clientlogin'; //

$connect = @mysql_connect ($host, $dbuser, $dbpass) or die ('Could not connect to MySQL!'); // attempt to connect
$select_db = @mysql_select_db ($dbname) or die ('Could not select database!'); // attempt to select database

?>

Link to comment
Share on other sites

My apologies but this is the first time i'm using php so i have no clue what that means... I tried using the setcookie() function and reformatted it as best as i could understand the link above. but it didn't work. any help would be great.

 

errors:



Warning: Cannot modify header information - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 3

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 4

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 4

 

new login.php:

<?php
require ('mysql.php');
setcookie(digicon,"yes");
session_start();


if (isset ($_POST['submit'])) { 
$username = $_POST['username'];
$password = md5 ($_POST['password']);
$success=0; 
									  

// See if the user exists
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
if ($r = mysql_query ($sql)) {
	$row = mysql_fetch_array ($r);
	$num = mysql_num_rows ($r);
	$success=1;
	}

	if ($num > 0) 
	{ 
		$_SESSION['users_id'] = $row['users_id'];
		$_SESSION['username'] = $row['username'];
		$_SESSION['loggedin'] = TRUE;
		exit;
	}

if ($success = 1){print 'Yes';exit;}
if ($success = 0){print 'No';exit;}
}	?>

 

 

 

Link to comment
Share on other sites

I made those changes... still have these errors:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 2



Warning: Cannot modify header information - headers already sent by (output started at /home/digiconm/public_html/login/login.php:1) in /home/digiconm/public_html/login/login.php on line 4

 

login.php

<?php
session_start();
require ('mysql.php');
setcookie(digicon,"yes");

if (isset ($_POST['submit'])) { 
$username = $_POST['username'];
$password = md5 ($_POST['password']);
$success=0; 
									  

// See if the user exists
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
if ($r = mysql_query ($sql)) {
	$row = mysql_fetch_array ($r);
	$num = mysql_num_rows ($r);
	$success=1;
	}

	if ($num > 0) 
	{ 
		$_SESSION['users_id'] = $row['users_id'];
		$_SESSION['username'] = $row['username'];
		$_SESSION['loggedin'] = TRUE;
		exit;
	}

if ($success = 1){print 'Yes';exit;}
if ($success = 0){print 'No';exit;}
}	?>

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.