Jump to content

[SOLVED] PHP Session Error


AKalair

Recommended Posts

Hi guys,

Everything was working fine earlier but I made some changes to the layout and now I'm getting this error.

 

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

 

ERROR: You must be logged in to view this

 

This is the code

 

<html>
<head>
<?php
session_start();
if (!$_SESSION['auth'] == 1) {
    // check if authentication was performed
    // else die with error
    die ("ERROR: You must be logged in to view this");
}
?>
<link rel="stylesheet" type="text/css" href="css.css" />
<title>Aarons Site</title>
</head>
<body>
<div id="navigation">
  <p class="headings">Navigation</p>
  <p><a href="index.html">Home</a></p>
  <p><a href="newuser.html">Register</a></p>
  <p><a href="login.html">Log In</a></p>
  <p><a href="members.php">Members Area </a></p>
</div>
<div id="content">Content Section
	<form action="logout.php" method="post">
<input type="submit" value="Logout" />
</form>


</div>
<div id="banner">
  <p>Banner</p>
  <p> </p>
  <p> </p>
</div>
</body>
</html>

 

Its meant to just display either welcome your logged in or, ERROR: You must be logged in to view this.

 

 

Link to comment
https://forums.phpfreaks.com/topic/125193-solved-php-session-error/
Share on other sites

You cannot have any form of output before the use of session_start().

 

Change

<html>
<head>
<?php
session_start();
if (!$_SESSION['auth'] == 1) {
    // check if authentication was performed
    // else die with error
    die ("ERROR: You must be logged in to view this");
}
?>

to

<?php
session_start();
if (!$_SESSION['auth'] == 1) {
    // check if authentication was performed
    // else die with error
    die ("ERROR: You must be logged in to view this");
}
?>
html>
<head>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.