Posted on 2005-03-23
Medium Priority
Last Modified: 2006-11-17
I'm trying to start a session for use on a number of pages. I get this error:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /var/www/html/dc/keywordeditor.php:8) in /var/www/html/dc/keywordeditor.php on line 15

What am I missing??

TIA Dinesh
Question by:dprasad
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 27

Expert Comment

ID: 13615456

must go before ANY output which includes:

- new lines or spaces before the opening php tag (<?php)
- html tags
- php output (including echo and print).

In an ideal situation session_start(); should be placed at the very top of your file before anything else
LVL 27

Accepted Solution

Diablo84 earned 1600 total points
ID: 13615479
Also take into consideration the factor of output from any include files you may have, php.net say it best:

QUOTE "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file."


This applies to anything that uses the http_headers, not only session_start (eg the header function and setcookie).

Assisted Solution

_Marcel_ earned 400 total points
ID: 13615527
Line 8 of keywordeditor.php would be the line that outputs the stuff.

If you can't move up the session_start(), then use an output buffer around the earlier lines.

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question