SSI - $context doesn't register login in from wordpress site

Started by guzh, January 07, 2012, 01:58:44 PM

Previous topic - Next topic

guzh

Hi,
I have implemented a ssi_login in my wordpress site. However when I log in, and go back to the wordpress site the $context array doesn't register that I've logged in. I guess this has something to do with including og files and the position of the login-form (in the sidebar), because I tried this on a standalone page and it worked perfectly.

If i dont declare global $context; in the sidebar page the login-form isn't displayed but "Hey, Guest." is displayed instead.

I've included the SSI.php in my wordpress theme's header.php

Does anyone know how to do this? :)

Andre N

What about $user_info ?
It is an array that holds info about the user and $user_info['is_guest'] will tell you if they are logged in or not.

require_once('path/to/SSI.php');
global $user_info;

Maybe Wordpress uses a variable named $context? You can check by loading Wordpress without calling SSI and using get_defined_vars (dump it out and see if theres a variable $context being used)
http://php.net/manual/en/function.get-defined-vars.php
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

MLM

You probably need to fix your cookie settings in the admin cp

Admin -> Configuration -> Server Settings -> Cookies and Sessions -> Use subdomain independent cookies

My Themes:

My Mods:

Unsolved Threads:
  • None atm...

guzh

Quote from: andre nickatina on January 07, 2012, 04:48:33 PM
What about $user_info ?
It is an array that holds info about the user and $user_info['is_guest'] will tell you if they are logged in or not.

require_once('path/to/SSI.php');
global $user_info;

Maybe Wordpress uses a variable named $context? You can check by loading Wordpress without calling SSI and using get_defined_vars (dump it out and see if theres a variable $context being used)
http://php.net/manual/en/function.get-defined-vars.php [nofollow]

when I var_dump $context it shows the correct array, so I guess Wordpress doesn't use it.. $context always shows is_guest as true (same with $user_info)..
It's strange that some of the ssi-functions works. like ssi_boardNews, ssi_todaysHolidays and so on. but not the login..

Quote from: MLM on January 07, 2012, 04:49:08 PM
You probably need to fix your cookie settings in the admin cp

Admin -> Configuration -> Server Settings -> Cookies and Sessions -> Use subdomain independent cookies
I'm not using a subdomain, so that shouldn't be necessary.. And I tried, but it didn't work...

I still think it has something to do with the inclusion of SSI.php..

Arantor

QuoteI'm not using a subdomain, so that shouldn't be necessary.. And I tried, but it didn't work...

Use subdomain independent cookies, then log out then back in. The cookie won't be regenerated with subdomain independence (and, as it happens, *path* independence too) until you relog back in.

Though without knowing exactly how you did integrate SSI.php into the page, it's impossible to tell for sure.
Holder of controversial views, all of which my own.


guzh

The forum is located at mywebsite.com/forum [nofollow] and the wordpress is installed at mywebsite.com/wordpress [nofollow] (i'll later make the wordpress available at mywebsite.com [nofollow]). I've included the SSI.php in the top of the header.php in my wordpress theme (which is built upon starkers html5 theme): require_once("../forum/SSI.php");

and the ssi_login-function is called in my sidebar.php, using the same code as in the example provided in the documentation.

the header and the sidebar is included in my index.php as well as page.php. In my index I've also called ssi_boardNews and it's working perfectly..

I've tried with subdomain independent cookies and log out and back in, and that didn't work ;\

Arantor

Hmm, that doesn't really clarify things. If SSI.php is included and board news is working, that means the functions are available but it doesn't do anything as far as checking variable scope.

So how exactly have you been trying to use $context? (Exact code, please)
Holder of controversial views, all of which my own.


guzh

I use $context like this:

global $context;
if (!$context['user']['is_guest']) {
  ssi_welcome();
  ssi_menubar();
  ssi_logout();
}
else {
  ssi_login();
}


If I remove global $context; above the if-else-statement the $context variable becomes empty.

And if I use the same code and including as I do in a single file not connected to wordpress it works perfectly. That's my reason for believing it has something to do with the including of files, or the way wordpress includes files..

Do you need anything else?

Thank you for you time, I really appreciate it! :)

Arantor

So what's the path to the forum and what's the path to the blog?

And what's the current cookie settings?
Holder of controversial views, all of which my own.


guzh

Quote from: guzh on January 08, 2012, 05:23:46 AM
The forum is located at mywebsite.com/forum [nofollow] and the wordpress is installed at mywebsite.com/wordpress [nofollow] (i'll later make the wordpress available at mywebsite.com [nofollow]).
I currently use relative path, should I use absolute path instead?

The current cookie settings is set to "subdomain independent cookies", but that doesn't work.

Arantor

Nope, changing the path from relative to absolute will make no difference.

QuoteThe current cookie settings is set to "subdomain independent cookies", but that doesn't work.

You *did* log out entirely then back in, right?
Holder of controversial views, all of which my own.


Andre N

If you can see the SMF cookie from your script, and get the cookie data and unserialize it properly, then this is just a session issue.
Try this:

require_once($_SERVER['DOCUMENT_ROOT'] . '/path/to/SSI.php');
$cookieData = unserialize($_COOKIE[$cookiename]);

if (!isset($_COOKIE[$cookiename])) {
    echo 'unable to see SMF cookie';
}

if (!$cookieData) {
    echo 'failed to unserialize SMF cookie';
} else {
    echo '<pre>;
    print_r($cookieData);
    echo '</pre>';
}


to see if you can actually get the information out of the cookie. If you get the message you can't see the cookie, it's not being set on the correct path. If you can't unserialize it, then we can try to figure out why not.
If you can get the cookie data, there's a session issue. Tell me what exactly you're trying to accomplish and I'll tell you how to do it with the API rather than through SSI
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

guzh

Quote from: arrowtotheknee on January 08, 2012, 05:40:44 PM
You *did* log out entirely then back in, right?
yeah, I even tried removing cookies, before and after I changed the local cookie setting. ;\

Quote from: andre nickatina on January 09, 2012, 10:53:47 AM
If you can see the SMF cookie from your script, and get the cookie data and unserialize it properly, then this is just a session issue.
The result was "failed to unserialize SMF cookie".

The exact thing I want to do is to create a login area to my forum in the sidebar of my wordpress theme. If the user is logged in it will display a welcome message like the one in ssi_welcome() - saying how many new messages the user got and if possible how many new replies to this users posts, as well as a logout text link. If the user is not logged in a login box is shown instead.
Also if it's possible it would be great if the login box is directed to the forum index, and the logout link(both on forum and on wordpress pages) is directed to the last visited page on the wordpress site.

Thanks! :)

Andre N

Post the cookie data here. Maybe Wordpress or your host is using magic quotes and adding slashes to your cookie data which will prevent it from unserializing properly. If we can see the cookie's serialized data string we can more easily determine why it won't unserialize, but I'm guessing Wordpress or your host is using magic quotes. SMF turns them off, but outside SMF it could be fouling up your serialized cookie data string with slashes.
Let's see what you got
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

guzh

When I dump $_COOKIE I get ["SMFCookie665"]=> string(0) "", if that's what you mean by posting cookie data.

Andre N

"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

guzh

that doesn't display anything. as you can see from my last post the SMF-cookie is made, but nothing is inside it.. ;\

Andre N

Your cookie needs to be set on path '/' or the SSI can't see it. The cookie is made and there is data in it. Try using the ssi command from the same directory as the SSI.php script and you'll see.
You can also look at the cookie from firefox using firecookie
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

guzh

ah, thanks. And I got two SMF cookies:
SMFCookie665 - a:4:{i:0;s:1:"6";i:1;s:40:"b472fa67a36e27b3ae54d4c0e1a8ef6f2ead7681";i:2;i:1515255024;i:3;i:2;}
SMFCookie801 - a:4:{i:0;s:1:"1";i:1;s:40:"1138f9cd1dc84e685e43c4c743d2ed4dbf1ee7b0";i:2;i:1515255934;i:3;i:2;}

and when I var_dumped cookie I also got the SMFCookie801 displayed (but it was hidden because of a z-index, so I didn't see it before.), and all quote signs was escaped/backslashed..

Andre N

So, turn on subdomain independent cookies option in SMF's admin panel. Your cookie needs to be set on path '/'

The SSI.php file will load Settings.php and get the correct cookie name $cookiename so don't worry about having 2 cookies

If the data has slashes in it, you either need to figure out why and make it stop, or more easily edit SSI.php to use stripslashes() before unserializing the cookie data
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Advertisement: