NameSilo

What's wrong with session_start()?

Spaceship Spaceship
Watch
Impact
145
Hello,

This is the code :

<? session_start(); ?>

When I access this page it gives :

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /mnt/storage/users/c/u/s/customcoding/index.php:1) in /mnt/storage/users/c/u/s/customcoding/index.php on line 1

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /mnt/storage/users/c/u/s/customcoding/index.php:1) in /mnt/storage/users/c/u/s/customcoding/index.php on line 1


To tell you the truth, I'm amazed with the results :]

How can I avoid this ugly error?

I believe I shouldn't see it...
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Output buffering is turned off. Contact your webhost and ask him to turn it off.

Or you can use the ob_start (); command which will buffer the headers for you.

Your Best Friend
-------------------------
http://us4.php.net/ob_start
 
0
•••
Hello, can you direct me into using ob_start() correctly, I just never used the ob functions. Can you give me a sample code?

I tried to put ob_start() above session_start() but nothing. :)

I do not know if this is a resolution to my current host or not.. I just added
error_reporting(0);
before
session_start();

Correct me please.
 
0
•••
Put ob_start() start above the session_start()

after ob_start(); use ob_getcontents(); (i think)

after that use ob_printcontents(); (think again)

then ob_end()

i think they are the right ones, the content ones, check in that outpout buffering link i gave you
 
0
•••
let me check, thanks! :)

Doesn't work now when I try to use header somewhere it says

Warning: Cannot modify header information - headers already sent by (output started at /home/designpo/public_html/index.php:1) in /home/designpo/public_html/includes/account_info.php on line 6
 
0
•••
then u reuse the ob start command..

The easiest thing to do is contact your web host and ask him to turn on php output buffering.

If u need a host that has it on. read my sig!
 
0
•••
If you accept credit cards globally, I could sign up..otherwise, no pp support :(
 
0
•••
check ur pms
 
0
•••
PHP:
<? @session_start(); ?>

or for more security script:

PHP:
<? ignore_user_abort(1); error_reporting(0);  session_start(); ?>

Regards
 
0
•••
i think this has been fixed ;) . he found a good host now i guess :P
 
0
•••
in my opinion using output buffering certainly is not the best solution, he would be best finding what is causing the error in the first place.
 
0
•••
Yea, it's been fixed now as xlusive said.. it was something with the host, that output buffering is Off, which globally turns off all session_start() usage.

Thanks though;
Ahmed
 
0
•••
as far as I am aware output buffering has nothing to do with sessions (and nothing is mentioned in the php manual). The reason the script failed in the first place was because the script output to the browser BEFORE session was started (even a space output causes this error).

The way you have fixed the problem is just a quick and dirty way to go about it and not actually fixing the problem itself.
 
0
•••
Ok it's a dirty way, and I like it.. anymore comments?
 
0
•••
just offering advise thats all, that is what you asked for
 
0
•••
If you used this code, then it'll error out:

<html>
BLAH...
<?php
session_start();
?>

What I use:

Code:
<?php
session_start();

echo <<<ENDDOC
MY DOCUMENT HERE
ENDDOC;

?>
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back