News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Session weirdness using SSI.php

Started by ozzyrocks_phillynorml, October 26, 2008, 02:58:31 AM

Previous topic - Next topic

ozzyrocks_phillynorml

Basically, my site is set up with a login/logoff box (depending on whether or not the user is logged in already). http://www.phillynorml.org/ [nofollow] - its on the left under the menu. The problem is that the global, $context, which I'm bringing into my program, always shows you as a guest; however, there IS a session_id.

Any ideas what I could be doing wrong here?

GamersGoop

I tried joining your site, but the visual verification image does not load, and neither does the Listen to the letters link.

To make this easier, just post the SSI includes login box code you're using. I will add the if ($context['user']['is_guest']) code to it.

ozzyrocks_phillynorml

That was probably my fault, I was changing some things around.

First, you must sign up at the forums (www.phillynorml.org/forum), then at www.phillynorml.org/involve/joinus [nofollow] , then you can try that login feature. It will log you in just fine, and when you go to /forum it'll show you logged in, but it won't while at www.phillynorml.org [nofollow]

GamersGoop

Post the SSI includes code you're using at the www.phillynorml.org page.

ozzyrocks_phillynorml

#4
Here, $phillynorml_forum_member is only set if $context['user']['is_guest'] is true.


<?php if (isset($phillynorml_forum_member)) {
                        
ssi_logout();
                      }
                      else {
                        
ssi_login("http://www.phillynorml.org/");
                      }
                
?>



Also there is no session_id from SMF, I was mistaken.

GamersGoop

#5
Odd. I am having a problem with the code displaying the welcome user message and all that too. Can you possibly try my site's existing code? It works for me nicely. You will need to edit the code so it fits your site how you want it. It will also display user avatar, unread messages, total messages... and all that.

<?php
{
global $context$txt$scripturl$settings$memberContext$modSettings$member_id$sc;

if($context['user']['is_logged']) {
$member_id $context['user']['id'];
loadMemberData($member_id);
loadMemberContext($member_id);

}

if ($context['user']['is_guest'])
echo '<tr class="titlebg">
<td style="padding-top: 6px; padding-left: 6px; padding-right: 6px; padding-bottom: 6px;" align="center" width="100%"><font color="#ffffff">Welcome, Guest</font></td>
</tr>
<tr class="windowbg2">
<td style="padding-top: 6px; padding-left: 6px; padding-right: 6px; padding-bottom: 6px;" class="windowbg2" valign="top" width="100%">
<div align="center"><strong><form action="'
$scripturl'?action=login2" method="post" accept-charset="'$context['character_set'], '">
<table border="0" cellspacing="1" cellpadding="0" class="ssi_table">
<tr>
<td align="right"><span class="smalltext"><label for="user">'
$txt[35], ':</label>&nbsp;</span></td>
<td><input type="text" id="user" name="user" size="9" value="'
, !empty($user_info['username']) ? $user_info['username'] : '''" /></td>
</tr><tr>
<td align="right"><span class="smalltext"><label for="passwrd">'
$txt[36], ':</label>&nbsp;</span></td>
<td><input type="password" name="passwrd" id="passwrd" size="9" /></td>
</tr><tr>
<td><input type="hidden" name="cookielength" value="-1" /></td>
<td><input type="submit" value="'
$txt[34], '" /></td>
</tr>
</table>
</form><span class="smalltext">Please <a href="index.php?action=login">login</a> or <a href="index.php?action=register">register</a>.</span></strong></div>
</td>
</tr>'
;

else
{
echo '<tr class="titlebg">
<td style="padding-top: 6px; padding-left: 6px; padding-right: 6px; padding-bottom: 6px;" align="center" width="100%"><font color="#ffffff">Hi, '
$context['user']['name'], '</font></td>
</tr>
<tr class="windowbg2">
<td style="padding-top: 6px; padding-left: 6px; padding-right: 6px; padding-bottom: 6px;" class="windowbg2" valign="top" width="100%">
<strong><div align="center">'
;

if (!empty($context['user']['avatar']))
echo '',$context['user']['avatar']['image'], '<br />';

}

if(allowedTo('pm_read'))
echo '
<span class="smalltext"> Total Messages: <a href="' 
$scripturl '?action=pm">' $context['user']['messages'], '</a></span><br />
<span class="smalltext"> Unread Messages: ' 
$context['user']['unread_messages'], '</span><br />';

if (!$context['user']['is_guest'])
echo '<div align="center"><span class="smalltext"><a href="'.$scripturl.'?action=profile">Profile</a>&nbsp;|&nbsp;</span><span class="smalltext"><a href="'$scripturl'?action=logout;sesc='$sc'">Logout</a></span></div></strong>
</td>
</tr>'
;

}
?>


This was a code from a TinyPortal block.

ozzyrocks_phillynorml

#6
Yea, the problem is that it's ALWAYS showing up as is_guest = 1.


public function beforeFilter() { // this function is run as part of the CakePHP API before anything is rendered to the screen. This file is not in the DocumentRoot
parent::beforeFilter();
global $context, $txt, $scripturl, $settings, $memberContext, $modSettings, $member_id, $sc, $user_info;
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
// This is for using forum information on the main page
/*print "<pre>";
print_r($context);
die("</pre>");*/

if (! $context['user']['is_guest']) {
$phillynorml_forum_member = $this->PhillynormlMember->findById($user_info['user']['id']);
if (! empty($phillynorml_forum_member)) {
$this->set('phillynorml_forum_member', $phillynorml_member);
}
}
}


If I uncomment that print/print_r/die section, you see the entire $context var which looks like this:
Quote
Array
(
    [user] => Array
        (
            [id] => 0
            [is_logged] =>
            [is_guest] => 1
            [is_admin] =>
            [is_mod] =>
            [username] =>
            [language] => english
            [email] =>
            [name] =>
            [smiley_set] => default
            [messages] => 0
            [unread_messages] => 0
            [avatar] => Array
                (
                )

            [total_time_logged_in] => Array
                (
                    [days] => 0
                    [hours] => 0
                    [minutes] => 0
                )

            [popup_messages] =>
        )
      .
      .
      .
)


ozzyrocks_phillynorml

So, nobody has a clue why SSI.php won't find the correct cookies and show the user as logged in?

青山 素子

It's because phillynorml.org and www.phillynorml.org aren't the same domain (to the computer). The login is setting a cookie for "phillynorml.org", but "www.phillynorml.org" won't see it because it's not the same thing.

Either synchronize the two sections to use the same domain, or enable sub-domain independent cookies on SMF. (All currently-logged in users would need to log out then in to get the new cookie format.)
Motoko-chan
Director, Simple Machines

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


ozzyrocks_phillynorml

#9
Ok, now it shows the logout link like it's supposed to, but when I click it I get this:

Quote
Session verification failed. Please try logging out and back in again, and then try again.

from the forums.

ozzyrocks_phillynorml

I looked at the $context variable, and the session_id is different. Any ideas?

[SiNaN]

I'm unfortunately not good with these kind of issue but can you if your settings are like this:

Admin CP >> Server Settings >> Feature Configuration

Enable local storage of cookies: unchecked
Use subdomain independent cookies: checked
Former SMF Core Developer | My Mods | SimplePortal

ozzyrocks_phillynorml


Advertisement: