I have discovered that I cannot use session management functions within a function library that I include in my
code. See example below:
File name: test.php
This works correctly:
<?php
function checkSession()
{
session_start();
if(!session_is_registered("SESSION"))
{
header("Location: logout.php");
exit();
}
}
checkSession();
//
// access to everything below requires a registered session
//
phpinfo();
?>
If I put the checkSession function in an external file to include with a require_once() - it fails!
checksession.inc
<?php
function checkSession()
{
session_start();
if(!session_is_registered("SESSION"))
{
header("Location: logout.php");
exit();
}
}
?>
test.php
<?php
require_once('checksession.inc');
checkSession();
//
// access to everything below requires a registered session
//
phpinfo();
?>
The error messages output are the following:
Warning: Cannot send session cache limiter - headers already sent (output started at /mba/reports/checksession.inc:13) in /mba/reports/checksession.inc on line 4
Warning: Cannot add header information - headers already sent by (output started at /mba/reports/checksession.inc:13) in /mba/reports/checksession.inc on line 7
Any help with this will be most appreciated.
David Reeves
Houston, Tx
dnreeves@swbell.net
<?php