Title: Setting Cookie from Outside WordPress
Last modified: August 18, 2016

---

# Setting Cookie from Outside WordPress

 *  Resolved [flicknut](https://wordpress.org/support/users/flicknut/)
 * (@flicknut)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/setting-cookie-from-outside-wordpress/)
 * I have my main site at [http://www.fantasyblitz.com](http://www.fantasyblitz.com),
   and then I have my blog at [http://www.fantasyblitz.com/blog/](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](https://wordpress.org/support/users/flicknut/)
 * (@flicknut)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/setting-cookie-from-outside-wordpress/#post-429165)
 * 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.
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/setting-cookie-from-outside-wordpress/#post-429167)
 * 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](https://wordpress.org/support/users/flicknut/)
 * (@flicknut)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/setting-cookie-from-outside-wordpress/#post-429179)
 * 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/](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
 *  [treelovinhippie](https://wordpress.org/support/users/treelovinhippie/)
 * (@treelovinhippie)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/setting-cookie-from-outside-wordpress/#post-429480)
 * 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.

## Tags

 * [authentication](https://wordpress.org/support/topic-tag/authentication/)
 * [cookies](https://wordpress.org/support/topic-tag/cookies/)
 * [external](https://wordpress.org/support/topic-tag/external/)

 * 4 replies
 * 3 participants
 * Last reply from: [treelovinhippie](https://wordpress.org/support/users/treelovinhippie/)
 * Last activity: [18 years, 10 months ago](https://wordpress.org/support/topic/setting-cookie-from-outside-wordpress/#post-429480)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
