My own $_SESSION variables are unusable in the forums (SMF 1.0.6)

Started by tumr, March 13, 2006, 12:55:52 AM

Previous topic - Next topic

tumr

Hi all,

I'm in love with the SMF boards, but I'm having trouble with one small but potentially important issue.  My session variables, which I set with my own login script, are not usable within the forums.  So, for example, I have session-dependent features in my header script that require the use of my own $_SESSION variables (e.g. username, as well as future fields which may not be covered by the $context[] variable).  Yet as soon as I enter the forum pages, the $_SESSION variables appear 'nulled' out (I when I try to, say, echo out their value, it returns a null answer).

However, the session variables have not been destroyed.  When I return to another page on my site, the proper data reappears within the SESSION variables.

You can see an example hxxp:www.tumr.com/forums/ [nonactive] (l/p is test/test).  When you're logged in, the header says 'logged in as test'.  When you go to the forums, the header will say 'you are not currently logged in', which might seem to indicate that the session variables have been destroyed.  Yet when you go back to the remainder of the site, you can see that you are considered to be logged in.


So my goal is to discover what seems to be hiding my session variables while I'm browsing the forums.  Can anyone point me in the right direction?

Alternatively, I'd like to figure out if there is a simple way to access the session data in the SMF session table.  I have searched the forums and have looked at the SSI.php and SSI_examples.php, but I have not been able to figure out how exactly how to go about this (I know how to make them login/logout and 'logonline()', but I do not know how to, say keep track of their total minutes online in a silent fashion like the forums do).

Undoubtedly this has been covered before and I've just failed to find the right thread, so if that's the case can someone point me to the right thread?  Thank you so much.

JayBachatero

I just tried to login and it works fine.  Forum and other links.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

tumr

Thanks for the reply.  Yes, the forum works fine.  However, as you can see in the header above the forum itself, it does not show that you're logged in.  So the forum will say "Hey test!" but my header will say "Sign Up"  "Log In"   and "you are not currently logged in" in spite of the fact that the forum knows that you're logged in.  If my header were able to successfully read the session variable in the forums, it would say "test's options" and "Logged in as test."

It seems to me that the error must arise because, for some reason, the session variables are inaccessible.  Just doing a straight 'echo' of my session variables in my header returns a null result, for example, when I browse the forums.

JayBachatero

Ok I see it now.  Well not much of a coder.  Can't help you here :-\
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

tumr

Quote from: JayBachatero on March 13, 2006, 01:15:34 AM
Ok I see it now.  Well not much of a coder.  Can't help you here :-\
It's OK.  Thanks for your help and your interest.  I'll keep my fingers crossed and hope that a coder takes some interest in this thread.

kegobeer

"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

tumr

Quote from: kegobeer on March 13, 2006, 07:23:07 AM
Post your custom code.
As far as the important part goes, it's just
<?
echo ("You are logged in as ".$_SESSION['username'].".");
?>


Specifically, in the index.template.php, I have the following code:
</head>';
$let_me_do_header = "YES";
global $sitename;
include("header.php");


The $let_me_do_header instructs my header not to echo out any values until the <body> tag (hence I have removed the "body';" line from the SMF default).  Then it echoes out the basic header data and explicitly calls on $_SESSION['username'] (it does not do so through an intermediary).

E.G., I do not do this: <?
$username = $_SESSION['username'];
?>
because I know that doing so would not work withing the *function* that is the index.template script.

I have even tried putting my code just below the loadSession(); tag in the actual index.php file, all to no avail...

kegobeer

"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

tumr

<?
include_once("settings.php");
header("Content-type: text/html; charset=utf-8");


if(!isset($let_me_do_header))//If I need the page to send everything from <html> to <body>
{
?>
<html>
<?
if(isset($pre_header_insert))
    {
        echo("$pre_header_insert");
    }
?>
<link rel="shortcut icon" href="<? echo $contenturl ?>/includes/favicon.ico" />
<head>
<title>
<?
echo (isset($pagetitle) ? $pagetitle : $sitename)." - ". $alltitle;
?>
</title>
<?
echo (isset($header_insert) ? $header_insert : "");
?>
<link rel="stylesheet" href="<? echo $contenturl ?>/includes/css.css" type="text/css" />
</head>
<?
}//If I need the page to do my header, that ends here.
echo (isset($bodytag_insert) ? $bodytag_insert : "<body>");
?>
<div id="the_body">
    <div id="top_menu">
        <div class='logo'><? echo $sitename ?></div>
        <br />
        <div class='menu_box'><a href='<? echo $contenturl ?>'>Home</a></div>
        <div class='menu_box'><a href='<? echo $contenturl."/forums/" ?>'>Community</a></div>
        <br />
        <?
        echo (!empty($_SESSION['username']) ? "" : "<div class='menu_box'><a href='$contenturl/membership/signup.php'>Sign up</a></div><div class='menu_box'><a href='$contenturl/membership/login.php'>Log in</a></div>");
        ?>
        <?
        echo (!empty($_SESSION['username']) ? "<div class='menu_box'><a href='$contenturl/membership/overview.php'>".$_SESSION['username']."'s Options</a></div>" : "");
        ?>
        <br />
        <div class="menu_text_box"><?
        echo (!empty($_SESSION['username']) ? "Logged in as <b>".$_SESSION['username']."</b>. <a href='$contenturl/membership/logout.php'>Log out</a>" : "You are not currently <a href='$contenturl/membership/login.php'>logged in</a>").". ";
        ?></div>
    </div><br />


So you don't have to wade through it too much, it asks, "Has the requesting page set $let_me_do_header?  If so, I'll skip everything down to the <body> tag."  Then the fun begins. So the code does little more than pump out some HTML and echo out the $_SESSION['username']. 

Thank you for your continued help with this.

tumr

Is this behavior by design?  I'm still stumped by this.  I've changed SMF's sessions settings back and forth but to no avail.

Advertisement: