Forum Moderators: coopster

Message Too Old, No Replies

php session_start problem

session_start - headers already sent

         

sanblasena

11:03 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



Hi, I am trying to do a session_start in PHp and I am getting these messages. It worked ok on my other server. Any ideas? Thanks in advance, Patricia

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/httpd/vhosts/site.com/httpdocs/shopping_cart.php:13) in /home/httpd/vhosts/site.com/httpdocs/shopping_cart.php on line 17

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/httpd/vhosts/site.com/httpdocs/shopping_cart.php:13) in /home/httpd/vhosts/site.com/httpdocs/shopping_cart.php on line 17
sessid= seesid2=

[edited by: jatar_k at 10:37 pm (utc) on Aug. 11, 2003]
[edit reason] generalized [/edit]

dwidmer

8:30 am on Aug 11, 2003 (gmt 0)

10+ Year Member



did you make sure that the session comes before you output anything? (before any echo or print or anything else)

waitman

9:25 am on Aug 11, 2003 (gmt 0)

10+ Year Member



Hello Patricia,

At the very top of you file, make sure you don't have any spaces or HTML content before the opening <?php tag. The opening <?php tag has to be the very first thing at the very beginning of the file.

Also, I am not sure what version of PHP you are using, however I believe that older versions were quite problematic with regards to session handling. You might check to see if session.auto_start is set in php.ini, and if you don't have the ability to modify php.ini you might try adding some PHP directives to .htaccess in your public directory.

Best Regards,

Waitman

[edited by: jatar_k at 10:38 pm (utc) on Aug. 11, 2003]
[edit reason] no sigs thanks [/edit]

vincevincevince

11:07 am on Aug 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



patricia - add
<?php ob_start();?>

to the very very top of httpdocs/shopping_cart.php
you may wish to change your full server path in the error to something generic eg /host/myaccount/httpdocs/ etc.. it's a security risk else, as well as making it harder for future users to see the relevance

waitman - you really should remove your company name and telephone number from your post (see the TOS & charter here regarding personal information, self promotion, and signatures).

sanblasena

4:39 am on Aug 14, 2003 (gmt 0)

10+ Year Member



Hi, Sorry I didnt get back with you sooner. No one responded for several days and I almost gave up.
Here is the code I was testing - I tried to keep it as simple as possible. I am beginning to think maybe there is some problem on my server that prevents me from doing it. They have the latest version of php, but I have had serveral problems before with this web hosting outfit. Let me know if you have any more ideas and thanks for you help. Pat

<HTML>
<HEAD>
<TITLE>test</title>
<META http-equiv=Content-Type content="text/HTML; charset=windows-1252">
</HEAD>
<body>
<?php ob_start();
session_start();
$mysessid = $PHPSESSID;
?>
<h1>test session start</h1>
</BODY>
</html>

waitman

5:56 am on Aug 14, 2003 (gmt 0)

10+ Year Member



i think you better remove that html stuff from the top.

you see, that will start the content flow out-the server.

when you try to set a header, it will barf. the headers always pop out before any content.

try echoing the top html head part for a quickie test.

echo '
<HTML>
<HEAD>
<TITLE>test</title>
<META http-equiv=Content-Type content="text/HTML; charset=windows-1252">
</HEAD>
<body>
';

make sure no whitespace no nothing before <?php!

then put your html in a template or layout or something...

take care,

waitman

6:05 am on Aug 14, 2003 (gmt 0)

10+ Year Member



sorry, i realized that perhaps you would be confused by the "headers" business.

you see, the way a server sets a cookie on a browser, it sends a specially crafted header line to the client. this header line tells the client to take the cookie "or else".

you can do a google search for something like "telnet HTTP/1.0" or "telnet localhost 80" or likewise to see how to check out the header content coming from the server.

if you want to watch what php spits out you can run php from the command line (without -q). Or at least you used to. For some reason on my freebsd machine with 4.3.2, it seems to not pop out the headers anymore (command line). didn't notice that before. anyone know about that one? i bet it has something to do with php-cli?

take care,