Re: Sessions - session_start()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



session_start() doesn't need to be the first line of your PHP code, it just needs to be called before any other output is performed.  Including any blank spaces or anything else.  If you have:

---
1:
2: <?php
3:   session_start();
4: ?>
---

It's not going to work because you have a blank line being output to the browser for interpretation.  Same problem would occur if you even had:

---
1: <?php   // Leading single blank space character
2:   session_start();
3: ?>
---

Output buffering may help in some cases, but I'd look at the error where it says:

"output started at /var/www/html/index.php:9"

Sounds like there's a way to solve this without resorting to output buffering.

In addition to the basic command reference listed below, check out the user contributed comments on these pages:

http://www.php.net/manual/en/function.session-start.php

http://www.php.net/manual/en/function.ob-start.php

According to the first comment, ob_end_flush() is called automatically at the end of your script, so it's not mandatory that you use it (but probably good 'complete' programming practice).

Good luck Jonas.

-TG

= = = Original message = = =

At 4:33 PM +0200 5/15/06, Jonas Rosling wrote:
>Den 06-05-15 16.00, skrev "Thomas Munz" <thomas@xxxxxxxxxxxxx>:
>
>>  put ob_start(); on the first line of your page
>>
>>  on Monday 15 May 2006 15:53, Jonas Rosling wrote:
>>>  Hi,
>>>  I've been building a site with PHP 5 on my develop machine. I've been
>>>  woring alot with session handling. For example I've been using
>>>  session_start() now and then depending on where the user/vistor are or are
>>>  doing.
>>>  But now I've moved the site to a host server with PHP 4.3.8 and now I keep
>  >> getting error messages all the time where I use session_start(). The error
>>>  message looks like this:
>>>
>>>  Warning: session_start(): Cannot send session cookie - headers already sent
>>>  by (output started at /var/www/html/index.php:9) in /var/www/html/index.php
>>>  on line 82
>>>
>>>  But I found out that if I put the tag in the absolute top of every page it
>>>  seems to work. But then I need to do alot of changes on all the pages.
>>>
>>>  Does anyone know if there's any workaround for this?
>>>
>>>  Thanks in advance // Jonas
>
>ob_start(); doesn't change anything in my case. But thanks anyway.
>
>// Jonas
>
>-

ob_start() was only half a possible solution:

http://www.weberdev.com/ob_start

There's the other part ( ob_end_flush ) that makes it work:

http://www.weberdev.com/ob_end_flush

However, as I understand it, using session_start() requires it to be 
the first line before everything else.

tedd


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux