Re: Cannot send session cookie
| From: | Michal Migurski | Date: | Mon, 12 Jul 2004 15:04:21 +0000 |
| Subject: | Re: Cannot send session cookie | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190237@lists.php.net to get a copy of this message | ||
> When experimenting with a few simple lines of code
>
> <script language='php'> ---- This is line 14
> session_start();
> </script>
>
> I get the following errors:
>
> Warning: session_start(): Cannot send session cookie - headers already sent by (output started
> at e:\http\cgi\a.php:14) in e:\http\cgi\a.php on line 15
What's on lines 1-13? Does it have whitespace or indents on line 14, like
in your mail? Any use of headers, get/set cookies, or sessions must happen
before any output such as HTML or print/echo is sent to the browser.
Generally, it's a good idea to have set-up code such as session_start() be
one of the very first things you call in a script.
Wrong:
<html><head /><body><?php session_start() ?></body></html>
Right:
<?php session_start() ?><html><head /><body /></html>
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html