Help - Search - Members - Calendar
Full Version: Cannot Send Session Cache Limiter
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
cogs
Hopefully I'm posting this in the right place.
I'm trying to use session variables to keep track of a user's name when they log into my server. I keep getting this error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

Here's the code I'm trying to execute: (the error is thrown on line 6, where <?php session_start(); ?> is.)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="default2.css" type="text/css" rel="stylesheet" />
<?php session_start(); ?>
<title>Main Page</title>

</head>

<body>
<div id="main">
<div id="bannertop">
<?php
if ($_SESSION['myusername'] == NULL){
echo"&lt;script Language='JavaScript' type='text/javascript' src='language_us.js'></script>
&lt;script>assign_var();</SCRIPT>
&lt;script language='JavaScript' src='nsutil.js'></script>
&lt;script>
var next_page='login.html';
function start_redirect()
{
document.location.href = next_page;
}

setTimeout('start_redirect()',2500);
</script>";
session_destroy();
}

$username = $_SESSION['myusername'];
echo "<h1 id='banner'>Hello, ' .$username.'!</h1>";

?></div>

<div id="foreground">

<h3 id="toptitle">Your current logins:</h3>
<?php include("display_table2.php");?>
</div>

<center>
<input type="button" name="newlogin" value="New Login" onclick="window.location = 'insert.html' " />
<input type="button" name="deletelogin" value="Delete Login" onclick="window.location = '/delete_form.php'"/>

<span id="logoutbutton">
<input type="button" name="logout" value="Logout" onclick="window.location = '/logout.php'"/></span>
</center>

</div>
</body>
</html>

Can anybody see where I'm going wrong here?
Let me know if you need any further info.

thanks,
ED
Ed
You can't call session_start after outputting content as it is sent as a header.

CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="default2.css" type="text/css" rel="stylesheet" />
<?php session_start(); ?>


Should be:
CODE
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="default2.css" type="text/css" rel="stylesheet" />
cogs
QUOTE(Ed @ Sep 29 2009, 01:27 AM) *
You can't call session_start after outputting content as it is sent as a header.

CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="default2.css" type="text/css" rel="stylesheet" />
<?php session_start(); ?>


Should be:
CODE
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="default2.css" type="text/css" rel="stylesheet" />


Hmm...
I need that file to be there because it includes a table that has to go after the banner. Guess I'll have to figure out another way to do it.
I'm going to have to also read up on headers.
Thanks for the quick response!
ED
NDBoost
QUOTE(cogs @ Sep 28 2009, 06:34 PM) *
Hmm...
I need that file to be there because it includes a table that has to go after the banner. Guess I'll have to figure out another way to do it.
I'm going to have to also read up on headers.
Thanks for the quick response!
ED


The way previously described makes no difference graphically.. You can use it the way described.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.