Problem integrating SMF Login Check into Wordpress!!!!

Started by wushdishmeen, June 23, 2010, 07:51:15 AM

Previous topic - Next topic

wushdishmeen

I use the is_not_guest function on every other subdomain on my server and it works perfectly.  Not to mention I use the function on several scripts that are all within their own folders in my root folder separate from SMF.   It's only wordpress that is having an issue with it.   But it DID work with wordpress a long time ago.   It wasn't until about 7-8 months ago that it stopped working and I could never get it to work again.   I started this thread so long ago and I still haven't figured it out.

As for my cookie settings they should be fine:

Enable local storage of cookies: OFF
Use subdomain independent cookies: ON
Use database driven sessions: ON
Allow browsers to go back to cached pages: ON
Seconds before an unused session timeout: 3600

I have to also mention that the results are different whether I am using FireFox or Internet Explorer as my browser.   With Firefox it redirects to the login page no matter what and with Internet explorer the page loads normally no matter what.   So it's even more confusion now.

Quote from: SlammedDime on July 14, 2011, 12:45:20 PM
The WP Super Cache plugin will not help you save bandwidth, so if that's the only reason you installed it, might as well uninstall it.  You should probably re-read the plugin's page on Wordpress' site to understand it's purpose.  What you are wanting to accomplish while using the WP Super Cache plugin is not easily done by any stretch of the imagination.

I don't use WP Super Cache anymore.   I switched to W3 Total Cache and the reason I use it is because I am on a shared server so it is necessary due to the high volume of traffic my site gets.   That's totally off tangent to the actual issue though.

Andre N

SO what ARE you getting in the $user_info array? It has to be set if either the api or SSI file successfully loaded...
Can you post the contents of the header file?
"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?"

wushdishmeen

You want the entire header.php file code?   Here it is with the coding added.

<?php
require_once('/home/xxxxxx/public_html/forum/smf_2_api.php');
if (
$user_info['is_guest']) {
header('Location: http://forum.xxxxxx.com/index.php?action=login');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type') ?>; charset=<?php bloginfo('charset') ?>" />

<title><?php

bloginfo('name');

$blog_description = get_bloginfo('description');

if (is_home () && !empty($blog_description) ) {

echo ' - '; echo $blog_description;

} elseif (is_category() ) {

echo ' - '; single_cat_title();

} elseif (is_single() || is_page() ) {

echo ' - '; single_post_title();

} elseif (is_search() ) {

echo __(' search results: ','easel'); echo esc_html($s);

} else {

echo ' - '; wp_title('',true);

}

 
?></title>

<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />

<?php if (!easel_themeinfo('disable_default_design') && !is_child_theme() && (easel_themeinfo('scheme') !== 'greymatter')) { ?>

<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style-default.css" type="text/css" media="screen" />

<?php } ?>

<link rel="pingback" href="<?php bloginfo('pingback_url') ?>" />

<meta name="Easel" content="<?php echo easel_themeinfo('version'); ?>" />

<?php if ( is_singular() && get_option( 'thread_comments' ) && !easel_themeinfo('disable_comment_javascript')) wp_enqueue_script( 'comment-reply' ); ?>

<?php wp_head(); ?>


</head>



<body <?php body_class(); ?>>



<div id="page-head"><?php do_action('easel-page-head'); ?></div>

<div id="page-wrap">

<div id="page">

<?php easel_get_sidebar('above-header'); ?>

<div id="header">

<?php easel_get_sidebar('header'); ?>

<div class="clear"></div>

</div>



<?php

if (!easel_themeinfo('disable_default_menubar') && function_exists('easel_menubar')) easel_menubar();

if (
easel_themeinfo('enable_breadcrumbs')) easel_breadcrumbs();

easel_get_sidebar('menubar');

get_template_part('layout', 'head');

?>


I also swapped out the smf_api I was using with the one you posted on this forum in a different thread.   So I'm using your version and it still gives the same issues.

SlammedDime

Quote
I don't use WP Super Cache anymore.   I switched to W3 Total Cache and the reason I use it is because I am on a shared server so it is necessary due to the high volume of traffic my site gets.   That's totally off tangent to the actual issue though.

It's actually not totally off tangent, exactly the opposite actually, and W3 appears to do some similar things to Super Cache.  They're caching entire pages of output or sections of output to serve back to users as static content, instead of serving them through PHP, which totally bypasses your attempts at validating a user, because PHP is never run, OR, the PHP code from header.php isn't being run because that aspect is already cached.

header.php is also a poor choice to place this code, as header.php is not one of the first files called by Wordpress, it is near in the middle or one of the last, as that is a theme file, not a core file.  You *should* be placing this code in your main Wordpress index.php file, as that is the bootstrap file of Wordpress and EVERY request for anything in Wordpress flows through that file.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

wushdishmeen

#24
If you read above to one of my first posts I had already contemplated the possibility of the caching plugin being the issue.   I said the exact same thing as you did already.  It wasn't the issue so the caching thing has now become moot as far as progressing in this issue.   Back then it would of been a good guess but right now it's already been looked at.   You should read the whole thread because you might be missing other stuff I've tried.

Like I said I used this code and it worked even with Super Cache installed back then and I didn't change anything except updating wordpress and plugins along the way.   So clearly an update caused something to happen.

I tried totally removing the caching plugin to see if that would make it work again and it didn't change a thing.   As for where to place the code I had it in the header.php file back then and it worked fine. 

Using the index.php file I get the same issues as with the header.php.  Just keeps redirecting to the SMF login whether I'm logged in or not.

Andre N

Put the code in the top of the index.php file and dump out the $user_info array and make sure the loadUserData function is being called
"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?"

wushdishmeen

#26
What do you mean by "dump out" the $user_info array?  Also how do you call the loadUserData function?  I've never used the API file before so if you could please write out the code you want me to try in your responses that would help a lot.

You sure it's not smfapi_loadUserSettings();  ???   It says that function loads the user an their cookie, as well as their settings.  There is no loadUserData function as far as I see


By the way,   I created a new PHP file called test.php and placed it in my wordpress folder.   I placed the coding at the top of the page and simply typed "TESTING" underneath the PHP and it works fine.   So it's not the coding it's wordpress that's clashing with it.   It shows the page with "TESTING" when I'm logged in and it redirects to the SMF login if I'm logged out.

Andre N

var_dump($user_info)
or print_r($user_info)

see what you get and post it pls
"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?"

wushdishmeen

Your responses are very vague but I'm trying to piece it together.

I had to remove the header redirect function otherwise I couldn't even read the output results...   So here is what I changed it to.   There is no loadUserData function though so I used the loadUserSettings function instead.

Like this
<?php
require_once('/home/xxxxxx/public_html/forum/smf_2_api.php');
smfapi_loadUserSettings();
if (
$user_info['is_guest']) {
}
var_dump($user_info);
?>


and I got this as the output
array(27) { ["groups"]=> array(1) { [0]=> int(-1) } ["possibly_robot"]=> bool(false) ["id"]=> int(0) ["username"]=> string(0) "" ["name"]=> string(0) "" ["email"]=> string(0) "" ["passwd"]=> string(0) "" ["language"]=> string(7) "english" ["is_guest"]=> bool(true) ["is_admin"]=> bool(false) ["theme"]=> int(0) ["last_login"]=> int(0) ["ip"]=> string(12) "26.192.14.63" ["ip2"]=> NULL ["posts"]=> int(0) ["time_format"]=> string(22) "%B %d, %Y, %I:%M:%S %p" ["time_offset"]=> int(0) ["avatar"]=> array(4) { ["url"]=> string(0) "" ["filename"]=> string(0) "" ["custom_dir"]=> bool(false) ["id_attach"]=> int(0) } ["smiley_set"]=> string(0) "" ["messages"]=> int(0) ["unread_messages"]=> int(0) ["total_time_logged_in"]=> int(0) ["buddies"]=> array(0) { } ["ignoreboards"]=> array(0) { } ["ignoreusers"]=> array(0) { } ["warning"]=> int(0) ["permissions"]=> array(0) { } }

That's with me logged in by the way and you can see that it's somehow pulling false info.   It says the ["is_guest"]=> bool(true)  and it also isn't recognizing that I'm an admin.

Andre N

the loadUserSettings() function is called automatically by the api, you don't need to call it again but it won't hurt. So the function isn't getting the session information inside wordpress, but it works outside...
it's not 'false info' per say, it just isn't finding your cookie or session info.

And it does this on Firefox only, and works on IE?

You have this code in your wordpress index.php file at the very top, right?
"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?"

wushdishmeen

yes I have it at the top of the index.php file now.

and no it doesn't work on either Firefox or IE.   It just gives different results.  With Firefox it keeps redirecting you to the login page whether you're logged in or not.   With IE it just loads the page normally without redirecting whether you're logged in or not.

Both don't recognize the login session.   So yea...  it's not grabbing the info.

Andre N

What does the $user_info array hold when you use IE?

check that and also, after you include the api put this:
echo $_COOKIE[$cookiename];
"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?"

Andre N

Your cookie is being found, and it's set correctly. I was able to unserialize it just fine. It looks like in the smfapi_loadUserSettings() function, this part:

if ($id_member != 0) {
// is the member data cached?
if (empty($modSettings['cache_enable']) || $modSettings['cache_enable'] < 2
            || ($user_settings = smfapi_cacheGetData('user_settings-' . $id_member, 60)) == null) {
    $request = $smcFunc['db_query']('', '
    SELECT mem.*, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type
    FROM {db_prefix}members AS mem
    LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = {int:id_member})
    WHERE mem.id_member = {int:id_member}
    LIMIT 1',
    array(
    'id_member' => $id_member,
    )
    );

    $user_settings = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);

    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
    smfapi_cachePutData('user_settings-' . $id_member, $user_settings, 60);
                }
}
}

is failing to get the user info out of the cache...
give me a minute and I'll tell you what to replace that with
"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?"

Andre N

#33
replace this:
if ($id_member != 0) {
// is the member data cached?
if (empty($modSettings['cache_enable']) || $modSettings['cache_enable'] < 2
            || ($user_settings = smfapi_cacheGetData('user_settings-' . $id_member, 60)) == null) {
    $request = $smcFunc['db_query']('', '
    SELECT mem.*, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type
    FROM {db_prefix}members AS mem
    LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = {int:id_member})
    WHERE mem.id_member = {int:id_member}
    LIMIT 1',
    array(
    'id_member' => $id_member,
    )
    );

    $user_settings = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);

    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
    smfapi_cachePutData('user_settings-' . $id_member, $user_settings, 60);
                }
}
}


with this:

if ($id_member != 0) {
// is the member data cached?
    $request = $smcFunc['db_query']('', '
    SELECT mem.*, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type
    FROM {db_prefix}members AS mem
    LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = {int:id_member})
    WHERE mem.id_member = {int:id_member}
    LIMIT 1',
    array(
    'id_member' => $id_member,
    )
    );

    $user_settings = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);
}


and see if that works for you
"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?"

wushdishmeen

#34
I see you updated the code and now it works properly.  However,  it didn't change anything as I am still getting redirected to the SMF login whether I'm logged in or not.

Here is the dump of $user_info again.  Same as before

array(27) { ["groups"]=> array(1) { [0]=> int(-1) } ["possibly_robot"]=> bool(false) ["id"]=> int(0) ["username"]=> string(0) "" ["name"]=> string(0) "" ["email"]=> string(0) "" ["passwd"]=> string(0) "" ["language"]=> string(7) "english" ["is_guest"]=> bool(true) ["is_admin"]=> bool(false) ["theme"]=> int(0) ["last_login"]=> int(0) ["ip"]=> string(12) "123.45.67.89" ["ip2"]=> NULL ["posts"]=> int(0) ["time_format"]=> string(22) "%B %d, %Y, %I:%M:%S %p" ["time_offset"]=> int(0) ["avatar"]=> array(4) { ["url"]=> string(0) "" ["filename"]=> string(0) "" ["custom_dir"]=> bool(false) ["id_attach"]=> int(0) } ["smiley_set"]=> string(0) "" ["messages"]=> int(0) ["unread_messages"]=> int(0) ["total_time_logged_in"]=> int(0) ["buddies"]=> array(0) { } ["ignoreboards"]=> array(0) { } ["ignoreusers"]=> array(0) { } ["warning"]=> int(0) ["permissions"]=> array(0) { } }

This is possibly the most annoying problem ever!!!   >:(

Andre N

I edited my above post, try it now.

I don't know if exposing your password hash is a security issue, but I would delete your post above with the cookie value :p
"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?"

wushdishmeen

You still never told me what the loadUserData function was?   There is no function with that name in the smf_2_api.php file and you told me I didn't need to include the loadUserSettings function so what exactly should I be putting after the call to the API?

Also,  that function that I just replaced seems to deal with the user data being cached within SMF and not wordpress.  What exactly were you attempting with the code you replaced and what is your ideas on what may be wrong?

Andre N

<?php
require_once( api file);
if ($user_info['is_guest']) {
    //redirect to smf login
}
?>

That's all you need. Make the change to the api file I put in the thread above and see if that works for you.
The function I meant was smfapi_loadUserSettings. When you require_once the api it will call the function for you.

Yes, we are bypassing the smf cache and geting the user info directly out of the db, so let's see if it works :)
"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?"

wushdishmeen

The code you said to replace is the same as it was a few seconds ago.   I already replaced it with the updated code and I placed the code in the index.php already and that's what I was saying was causing the same issue.  It redirects to the login page whether I'm logged in or not.

Nothing has changed.   I also for now replaced the header redirect with just an echo function that says "GUEST" at the top of the page if it recognizes me as a guest.    It still says Guest...  so whenever that disappears from the page it will mean that it's finally recognizing me as logged in.

Looks like we're still stuck at square one.   I hope you aren't tapped out.   If you can get this to work I would be willing to compensate you if that motivates you.  This is extremely important that it works.

Andre N

I'm not tapped. And I think we're getting closer.
Could you pm me your ftp login details? It would be a lot faster that way...
"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: