Why can't I use session

This is a discussion on Why can't I use session within the PHP Language forums, part of the PHP Programming Forums category; Hi, When I run this script: <?php session_start(); $_SESSION['test'] = "Session er smart"; echo $_SESSION['test']; ?> ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-29-2003
Ricki Susic
 
Posts: n/a
Default Why can't I use session

Hi,

When I run this script:

<?php
session_start();
$_SESSION['test'] = "Session er smart";
echo $_SESSION['test'];
?>

I get this error-message:

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/hotel/svp/WWW/html/php/auth.php:9) in /hotel/svp/WWW/html/php/auth.php on
line 10

Warning: session_start() [function.session-start]: Cannot send session cache
limiter - headers already sent (output started at
/hotel/svp/WWW/html/php/auth.php:9) in /hotel/svp/WWW/html/php/auth.php on
line 10
Session er smart


What is wrong?

Ricki


Reply With Quote
  #2 (permalink)  
Old 09-29-2003
Erwin Moller
 
Posts: n/a
Default Re: Why can't I use session

Ricki Susic wrote:

> Hi,
>
> When I run this script:
>
> <?php
> session_start();
> $_SESSION['test'] = "Session er smart";
> echo $_SESSION['test'];
> ?>
>
> I get this error-message:
>
> Warning: session_start() [function.session-start]: Cannot send session
> cookie - headers already sent by (output started at
> /hotel/svp/WWW/html/php/auth.php:9) in /hotel/svp/WWW/html/php/auth.php on
> line 10
>
> Warning: session_start() [function.session-start]: Cannot send session
> cache limiter - headers already sent (output started at
> /hotel/svp/WWW/html/php/auth.php:9) in /hotel/svp/WWW/html/php/auth.php on
> line 10
> Session er smart
>
>
> What is wrong?



As the error says: You are sending things before you do your sessionstuff.
Solution: don't. Put you sessionlogic on top of the page.

Regards,
Erwin Moller
>
> Ricki


Reply With Quote
  #3 (permalink)  
Old 09-29-2003
Phil Roberts
 
Posts: n/a
Default Re: Why can't I use session

With total disregard for any kind of safety measures Erwin Moller
<since_humans_read_this_I_am_spammed_too_much@spam yourself.com>
leapt forth and uttered:

> As the error says: You are sending things before you do your
> sessionstuff. Solution: don't. Put you sessionlogic on top of
> the page.


Actually you just need to make sure you call session_start() before
any output.


--
There is no signature.....
Reply With Quote
  #4 (permalink)  
Old 09-29-2003
Jeffrey Silverman
 
Posts: n/a
Default Re: Why can't I use session

On Mon, 29 Sep 2003 11:52:27 -0500, Phil Roberts wrote:
<snip!>
> Actually you just need to make sure you call session_start() before any
> output.


Including whitespace!

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Reply With Quote
  #5 (permalink)  
Old 10-07-2003
Shawn Wilson
 
Posts: n/a
Default Re: Why can't I use session

Ricki Susic wrote:
>
> Hi,
>
> When I run this script:
>
> <?php
> session_start();
> $_SESSION['test'] = "Session er smart";
> echo $_SESSION['test'];
> ?>
>
> I get this error-message:
>
> Warning: session_start() [function.session-start]: Cannot send session
> cookie - headers already sent by (output started at
> /hotel/svp/WWW/html/php/auth.php:9) in /hotel/svp/WWW/html/php/auth.php on
> line 10
>
> Warning: session_start() [function.session-start]: Cannot send session cache
> limiter - headers already sent (output started at
> /hotel/svp/WWW/html/php/auth.php:9) in /hotel/svp/WWW/html/php/auth.php on
> line 10
> Session er smart

You can't send anything to the browser before starting your session, not even a
single blank line or space. Make sure your file starts like this:

-------------Start of file---------------------
<?PHP
session_start();

Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0