View Full Version : Need help with a function for redirecting

02-19-2012, 02:33 PM
I made this code as a function:

function isLoggedIn()
if (isset($_SESSION['ulogovan']))
echo 'You are logged as: ' . $_SESSION['ulogovan'];

echo 'Your are not logged...';



Ok, the problem is:
If I upload the whole project to my web server and try the code I got all the time the error because of the "header()" function and php.ini settings something like this:

Warning: session_start() [function.session-start]: Cannot send session cache limiter...


Warning: Cannot modify header information - headers already sent by...

Ok, I know why this happen but how to make an IF-ELSE checking and redirecting to another page if the ELSE statement is reached without the "header()" function?

I have to track the logged user session too so I know on other pages if the real logged in user are the one who visits the member area...

I have no option to change the php.ini file on the server because it is out of my administration reach and I have no access to that.

Any idea?

02-19-2012, 04:02 PM
session_start() must be the first line in your php code/page.

You can't have anything outputted to the browser before session_start or a header.

02-20-2012, 01:12 AM
Sorrty but dosen't work.
I got from the admin personal a mail where they say the output_bufferin is set to off in php.ini and it will be off.

Any idea pls ?

02-20-2012, 11:52 AM
So you deleted echo 'Your are not logged...'; and moved session_start() to the very top of the page?

02-20-2012, 09:10 PM
Thank's for suggestion, it worked!