Hey guys,
I need some quick help with an error I am getting in my login page. I am taking a php course for work and stuck on this error. The exact error is:
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/scott321/public_html/dl.php:1) in /home/scott321/public_html/login.php on line 12
Warning: Cannot modify header information – headers already sent by (output started at /home/scott321/public_html/dl.php:1) in /home/scott321/public_html/login.php on line 14
I did some research on this and supposidely it is because of blank spaces after my php closing statement. However I checked this everywhere and do not see any issues.. my db is set up with the table correctly. Below is a copy of the 3 php files I am using (dl.php, login.php, checklogin.php)
dl.php:
[CODE]<?php
$username=”scott321_user”;
$password=”********”;
$database=”scott321_contacts”;
$con = mysql_connect(localhost,$username,$password);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db($database, $con) or die(“Couldn’t open $database: “.mysql_error());;
?>
login.php:
[CODE]<?php
if($_POST[‘Submit’]){
include(“dl.php”);
$userid = $_POST[‘userid’];
$password = $_POST[‘password’];
$query = “select * from users where userid=’$userid’ and password=’$password'”;
$result = mysql_query($query,$con) or die(‘Error: ‘ . mysql_error());
$num = mysql_num_rows($result);
mysql_close();
if ($num > 0 ){
session_cache_limiter(‘public’);
session_start();
$_SESSION[‘views’] = 1;
header (“Location: show_contacts.php”);
exit();
}
else {
echo “invalid userid or password try again”;
}
}?>
<!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=utf-8″ />
<title>Untitled Document</title>
<script type=”text/javascript”>
function Validateform(){
var userid=document.form1.userid;
var password=document.form1.password;
if ((userid.value==null)||(userid.value==””)){
alert(“Please enter userid “);
userid.focus();
return false;
}
if ((password.value==null)||(password.value==””)){
alert(“Please enter password “);
password.focus();
return false;
}
return true;
}
</script>
<style type=”text/css”>
.style1 {
text-align: center;
}
</style>
</head>
<body>
<form action=”<?=$_SERVER[‘PHP_SELF’]?>” method=”post” id=”form1″ name=”form1″ onsubmit=”return Validateform();”>
<table width=”400″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td> UserID</td>
<td> <input name=”userid” id=”userid” type=”text” ></td>
</tr>
<tr>
<td> Password</td>
<td> <input name=”password” id=”password” type=”password”></td>
</tr>
<tr>
<td colspan=”2″>
</td>
</tr>
<tr><td colspan=”2″ class=”style1″>
<input name=”Submit” type=”submit” value=”Log In” ></td>
</table>
</form>
</body>
</html>
checklogin.php:
[CODE]<?
session_start();
if ($_SESSION[‘views’] != 1) {
header (“Location: login.php”);
exit();
}
?>
Any help is appreciated greatly!