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?

 

 

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
}
?>

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

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.