Page 2 of 2

Posted: Fri Aug 25, 2006 4:27 am
by mohson
There is obviosly somethign wron with the $_SESSION code in both the error message code and in the code which calls it; php code 1 and 3 in above post.

VBut can anyone spot what the problem is - why isnt it calling the error message.

Posted: Fri Aug 25, 2006 5:03 am
by volka
session_start() by default tries to set a cookie with the session id.
a cookie is a http header.
http headers have to be sent before the reponse body.
any output belongs to the reponse body.
at line 2 of /export/TSG-Z/web-source/organisation/plCMS/organisation some was output.

Posted: Fri Aug 25, 2006 5:21 am
by mohson
So with regards to displaying the error message are you saying

Code: Select all

<?
if(isset($_SESSION['errmsg'])){
echo $_SESSION['errmsg'];
unset($_SESSION['errmsg']);
}
?>
this needs to be at the top of the homepage with no spaces. For the error message to show??

Posted: Fri Aug 25, 2006 6:14 am
by volka
no, only session_start() and additional header() calls have to be made before any output (via echo,print ect and characters outside of a php block) is sent to the client.

Posted: Fri Aug 25, 2006 6:34 am
by mohson
Volka im really sorry but ive read your post over and over again. I dont understand.

Lets keep it simple.

What should I change on this code to make the error message appear.

The code listed above works fine it throws the unauthorized user back to the homepage it just doesnt show them the error message.

What should I change to make this error message appear?

Posted: Fri Aug 25, 2006 6:52 am
by richo
Do you know for sure the session is working properly? Maybe you need to start the session on each page (ie - the one that is creating the session and the one that is detecting if it has been set).


See here to find out more:

http://uk2.php.net/function.session-start

(i'm afraid i can't try your code out as i don't have access to php localhost right now)

Posted: Fri Aug 25, 2006 8:21 am
by volka
mohson wrote:Lets keep it simple.
as simple as it gets ;)

Code: Select all

<?php
echo 'xyz';
session_start(); // won't work, output before session_start(), warning: cannot modifiy yadda yadda
?>

Code: Select all

<?php
session_start(); // session_start before any output for this htttp-request, no problem.
echo 'xyz';
?>
php tells you exactly which line of code caused the output:
mohson wrote:headers already sent by (output started at /export/TSG-Z/web-source/organisation/plCMS/organisation:2 in export/TSG-Z websource/organisation/PL/CMS/Uorgs.htm on line 6.