• Resolved flicknut

    (@flicknut)


    I have my main site at http://www.fantasyblitz.com, and then I have my blog at http://www.fantasyblitz.com/blog/.

    When users register on my main site, it creates two accounts: one in my main database and one in the WordPress database. The accounts share the same username and password.

    Now when users login to my main site, I want to set the WordPress cookie so they don’t have to login again on my blog. How can I do this? Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter flicknut

    (@flicknut)

    Okay here is the solution:


    // Begin WordPress Cookie Handling require_once("blog/wp-includes/pluggable-functions.php");
    $siteurl = "http://www.fantasyblitz.com";
    $blogurl = "http://www.fantasyblitz.com/blog";
    $cookiehash = md5($blogurl);
    define('COOKIEHASH', $cookiehash);
    define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
    define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
    define('COOKIE_DOMAIN', false);
    wp_setcookie($user_username, $login_password, false, $siteurl, $siteurl, $remember);
    // End WordPress Cookie Handling

    Firefox is great for troubleshooting problems with your cookies. Just login to WordPress the regular way, and then compare that cookie to the one you are trying to create outside of WordPress.

    As it usually happens… after 5 months somebody will find this thread and will desperately asking you: where to put this code? 🙂

    Thread Starter flicknut

    (@flicknut)

    Okay here are some adjustments to the code…there was a bug with destroying the cookie when logging out.

    You put this code immediately after you check authentication on your main site (in this case http://www.fantasyblitz.com/login/):


    // Begin WordPress Cookie Handling require_once("blog/wp-includes/pluggable-functions.php");
    $blogurl = "http://www.fantasyblitz.com/blog";
    $cookiehash = md5($blogurl);
    define('COOKIEHASH', $cookiehash);
    define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
    define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
    define('COOKIE_DOMAIN', false);
    wp_setcookie($user_username, $login_password, false, $blogurl, $blogurl, $remember);
    // End WordPress Cookie Handling

    Here’s the code for logging out:


    // Begin WordPress Cookie Handling
    require_once("blog/wp-includes/pluggable-functions.php");
    $blogurl = "http://www.fantasyblitz.com/blog";
    $cookiehash = md5($blogurl);
    define('COOKIEHASH', $cookiehash);
    define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
    define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
    define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', $blogurl . '/' ) );
    define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', $blogurl . '/' ) );
    define('COOKIE_DOMAIN', false);
    wp_clearcookie();
    // End WordPress Cookie Handling

    Bah, this isn’t working for me… any ideas?

    I’m trying to integrate the login in phpizabi and wordpress.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Setting Cookie from Outside WordPress’ is closed to new replies.