SMF in WordPress

For some reason, while using WordPress and including SMF’s SSI.php, it would not detect my logged in SMF session. Baffled and almost thinking this was a SMF bug of some sorts, I began to debug this process.

Well it turns out it is sorta a SMF old PHP support issue, but the problem lies in WordPress. This is the function in WordPress wp-includes/load.php

The problem here, is that they add magic quotes to the cookie. Not quite sure why they are even doing this. But it broke adding SMF. The part in SMF which failed because of this is in SMFs Sources/Load.php in the loadUserSettings function

Because of old PHP support in SMF, its trying to combat a cookie security issue that existed below PHP 4.3.9. Now I don’t use that version, but I rather not strip out the code. The preg match was failing because it was not finding that valid string in the cookie. Since all the double quotes where escaped with a slash \.

For my code, I called in Settings.php from SMF and then did a stripslashes on the cookie. Then I included SSI.php, with the results I expected of it finding my active SMF session.

I should note because SMF uses a lot of global variables, that I had to globalize all of those before hand. I just borrowed the globals from SSI.php and put them into that scripts function.

7 comments on “SMF in WordPress”

  1. nuno

    Can I plly this to smf 1.1 ?

    I’ve try to do this in my wordpress header, and the result was:

    Warning: require_once(/QueryString.php): failed to open stream: No such file or directory in /home/www/forum.domain.com/public_html/SSI.php on line 62 Fatal error: require_once(): Failed opening required ‘/QueryString.php’ (include_path=’.:/usr/local/php/lib/php’) in /home/www/forum.domain.com/public_html/SSI.php on line 62

    Any ideas?

    • SleePy

      Check your SMF Settings.php file, that usually means that the $sourcedir is missing or isn’t defined. Its also possible the function you are using it in didn’t global $sourcedir.

  2. Dinko

    Thanks a lot man. Great job.

    Same error. My sourcedir isn’t missing and its defined. But if you add this line
    if (isset($_COOKIE[$cookiename]))
    $_COOKIE[$cookiename] = stripslashes($_COOKIE[$cookiename]);
    right after

    require_once(dirname(__FILE__) . ‘/Settings.php’);

    in ssi.php it will work. But now logout doesn’t work.

    • SleePy

      I would assume this would be based on how you generated the session link. I haven’t tested passing login/out data through from WordPress. My code was to get SMF sessions to be recognized while working in a WordPress base

Leave a Reply

Highslide for Wordpress Plugin