[RESOLVED] Warning: session_start(): Cannot send session cookie - headers already sent
Hi,
I am getting these errors :
Code:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/box/public_html/im/launch.php:29) in /home/box/public_html/im/launch.php on line 40
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/box/public_html/im/launch.php:29) in /home/box/public_html/im/launch.php on line 40
Warning: Cannot modify header information - headers already sent by (output started at /home/box/public_html/im/launch.php:29) in /home/box/public_html/im/launch.php on line 42
Warning: Cannot modify header information - headers already sent by (output started at /home/box/public_html/im/launch.php:29) in /home/box/public_html/im/launch.php on line 43
Here are lines 40 to 46 :
Code:
session_start();
$_SESSION['sid'] = "sid";
setcookie("sid", sid, time()+3600);
setcookie("sid", $_GET["uname"], time()+3600);
$CheckInTime = Time();
$query="INSERT INTO `NetImOn` (`U_Name`, `LoginTime`, `SessionId`) VALUES ('".$_GET["uname"]."', '".$CheckInTime."', '".session_id()."')" or die(mysql_error());
mysql_query($query);
Can anyone please tell me what is wrong with the following error, thank you.
Jf3000
Blank space above the php tag or below the final php tag
It is not intuitive but ...
if <?php is at line 2 of your script and a blank line is above it then that can cause problems such as the php header function not working.
I had a HEADER session_regenerate error because a script called by require_once () or include () had 1 blank line below the closing php tag !!
?>
BLANK LINE WAS HERE
echo statements will also be a problem if they precede the header function call.
I wonder if die() or any other statements which write to the screen would be just as bad as echo () in this situation.
Warning: session_start(): Cannot send session cookie - headers already sent
100% working solution
Step one :- Search & Open PHI.INI
Step Two:- Search session.cache_limiter
Step three:- put " public " in front of session.cache_limiter
Like
session.cache_limiter =public
Thats it .
Regards
Shahzad Arain :)
[Do not post personal contact info here - MOD]
i get the same message using dreamweavers built-in log-in wizard
Hi, I used Dreamweavers "Log-in User" wizard to create the php code that binds to the database and upon execution, i get the following message:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent in /Users/xxx/Sites/xxxx/login.php on line 10
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Users/xxx/Sites/xxxx/login.php:10) in /Users/xxx/Sites/xxxx/login.php on line 10
Here is my code... what could be wrong?
Code:
<?php virtual('/~xxx/xxxx/Connections/yyyy.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['GroupID'])) {
$loginUsername=$_POST['GroupID'];
$password=$_POST['Password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/~xxx/xxxx/main.php";
$MM_redirectLoginFailed = "/~xxx/xxxx/authorizationfailed.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_yyyy, $yyyy);
$LoginRS__query=sprintf("SQL query",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $yyyy) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!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>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<table width="200" border="1">
<tr>
<td>User Name</td>
<td><input type="text" name="GroupID" id="GroupID" /></td>
</tr>
<tr>
<td><p>Password</p>
</td>
<td><input type="text" name="Password" id="Password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
I appreciate the help.