Forum Moderators: coopster
I have a question which no doubt will pose you people with nor problem whatsoever to help me with
I have written a function to display coherent error messages throughout my entire site
I pass it 2 vars, which contain only text
one is for the document's title, one for the error message in the body (ofcourse there is formatting etc, but thats all inside the function and CSS)
problem is, when the function gets called, it loses state, ie.: the generated page doesnt start the session properly, even though I do this inside the function
what can I do to prevent this?
some elements of the site are only shown when a user is logged in, so the effects are rather dramatic
any help would be appreciated
but to make it easier:
if (isset($_SESSION('valid_user') and func_status_check($_SESSION['uid'])!= 'admin'){
code
$var1 = "Access denied";
$var2 = "You arent allowed to access this part of the site";
func_error_msg($var1, $var2);}
thats it...al theres to it. I dont have a problem with my sessions..perhaps you should take more time to read. ofcourse the current user is logged in.....I said that in my previous didnt I?
It just doesnt maintain state when the fucntion is called
the function is very simple
function func_error_msg($var1, $var2)
{
session_start(); //doesnt make a difference?>
<html>
<title><? echo $var1;?></title>
<body> <? echo $var2;?>
</body>
</html<
<? }
theres more html in the fucntion...but thats it, left out most to give you an idea
edit: no I am not checking inside the fucntion if the use is logged in...im doing that right at the start of the page....so I just figured it would be in scope
the function is included once via a sitewide include file
[edited by: dmmh at 10:22 pm (utc) on Jan. 16, 2005]
You should also drop the session_start() inside the function if you had already started it in the page. There's absolutely no reason for you do start it again.
you are right...but I was just using it as an example.
Like I said....user is logged in. I just used it as a way to make clear to you in general form how the fucntion is called. Bad example
But like I said, I use this function for a great many scenarios (i have lots of check etc, if someone can edit posts, topics, is allowed access to admin ctrl panel, stuff like that, if not, I use this function)
and I know I dont have to session_start() again, just threw it in there in case someone was wondering if it would work :p
You need fix this, since it is the condition that triggers the error: isset($_SESSION('valid_user') and func_status_check($_SESSION['uid'])!= 'admin'
Debug the page using var_dump($_SESSION) and see the result