Jump to content

Cannot send session cache limiter - headers already sent


Mal1

Recommended Posts

I'm trying to start a session in my header.php file so it's included on every page so that I can have a "Log in | Register" button if people are signed in or a "Logout" button if people are already signed in.

 

I'm getting the message:

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /homepages/33/d440142155/htdocs/LuxuryLiving/index.php:14) in /homepages/33/d440142155/htdocs/LuxuryLiving/layout/header.php on line 3

 

As far as I'm aware this is caused by the session start not being the first line of code? I could place

 

<?php
session_start();
?>

 

On each individual page but A) would this not be attempting to start the session over and over again on every page (I'm sure it would ignore secondary attempts but this can't be the right way to do it?) and B) it just doesn't seem like the right way to do it.

 

The code I have is as follows:

 

Index page (similar for all pages)...

 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>The Luxury Living Network - Scotland</title>
<link href="/css/network.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="/images/network.ico" type="image/x-icon" />
</head>
<body>
<div id="container">
<?php include('layout/header.php'); ?>
<div id="content">...

 

Within the header.php...

 

<?php
session_start();?>
<?
$page = $_SERVER['SCRIPT_NAME'];
?>
<div id="header">
<div id="logo">
<a href="http://www.luxurylivingscotland.co.uk">
<img src="http://www.luxurylivingscotland.co.uk/images/logo.jpg" alt="Luxury Living Logo" name="luxurylivinglogo" id="luxurylivinglogo" />
</a>
</div>


<? if (isset($_SESSION['first_name']))
{
include ('layout/logout.php');
}
else
include ('layout/signin.php')
?>


</div>

<div id="menu" align="center">
<ul>
<li><a href="/index.php">Home</a></li>
<li><a href="/about.php" <?php if ($page == "/about.php"){ echo "class='active'";} ?>>About Us</a></li>
<li><a href="/categories.php" <?php if ($page == "/categories.php"){ echo "class='active'";} ?>>Categories</a></li>
<li><a href="/member/offers.php" <?php if ($page == "/member/offers.php"){ echo "class='active'";} ?>>Offers</a></li>
<li><a href="/members.php" <?php if ($page == "/members.php"){ echo "class='active'";} ?>>Member's Area</a></li>
<li><a href="/contact.php" <?php if ($page == "/contact.php"){ echo "class='active'";} ?>>Contact Us</a></li>
</ul>
</div>

 

Any ideas what I'm doing wrong?

Link to comment
Share on other sites

Each "page" is a separate request to the server. So, every page that needs to access the session data must start a session.

 

The "second" (and subsequent) pages will end up with the "session" that was started on the first page. So, yes, it does make it seem like "start" is the wrong verb to use here. But that's the way it is. And if someone goes straight to the "second" page, without accessing the first page, then that page will actually "start" the session (so maybe "start" is the right verb to use here).

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.