Jump to content

[SOLVED] HELP - php error when setting session cookie


aminnuto

Recommended Posts

I have an empty php file with this code in it.

 

<?php
session_start();

if ($_SESSION['box'])
{
} else {
include('/home/maine/www/inc/box.inc');
$_SESSION['box'] = "value";
}

?>

 

 

and this page works perfectly.  Its supposed to check for the session cookie and if its not set, show this file, but if it is set, dont show the file.

 

 

BUT,

when i insert this code on to the pages through website, they all show this error.

 

 

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/main/public_html/page.php: in /home/main/public_html/page.php on line 13

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/main/public_html/page.php.php: in /home/main/public_html/page.php on line 13

 

 

 

 

 

None of the other pages set a cookie.  So, the code works when its by itself, (on its own blank filename.php page but when I put it on anyother.php file page, i get this error.  Anyone know how to get around this?

 

 

Link to comment
Share on other sites

I always use this little bit of code when playing with sessions:

 

<?php
session_start();

header("Cache-control: private");   // IE6 Fix for Sessions

ob_start();
?>

 

Also when checking a Session I like to use the

IsSet()

function:

 

<?php
if(isset($_SESSION['box'])) {
  // Session is set
} else {
  // Session is not set
}
?>

Link to comment
Share on other sites

correction, this code gives me the same result.  works fine when on a page with no other  php code.

 

<?php
session_start();

header("Cache-control: private");   // IE6 Fix for Sessions

ob_start();
?>


<?php

if(isset($_SESSION['box'])) {
} else {
include('/home/main/www/inc/box.inc');
$_SESSION['box'] = "value";
}
?>

 

 

but when i put it on a page with other php code, it does this.

 

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/main/public_html/phppage.php: in /home/main/public_html/phppage.php on line 13

Warning: Cannot modify header information - headers already sent by (output started at /home/main/public_html/phppage.php: in /home/main/public_html/phppage.php on line 15

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.