Cookie Path Plugin For WordPress 2.0 (root Cookie)

line Tags: ,

UPDATE: This Plugin has been updated, the below links to the new file, but please comment on the new post, thanks.

I’ve been busy this AM, my site is a little bit integrated with WordPress, basically I call the header and footer from WP so that my custom code changes themes when WordPress does :)

I want to take it further and use the authentication cookie, so that my code recognizes me when I log in (in the same way WordPress does). In order for linickx.com to see the cookie set by linickx.com/blog, I need to change the COOKIEPATH. The change is actually quite simple, in fact the “set cookie” function is a pluggable one :D

The function / plugin I’ve written is really simple, all I’ve done is change the PATH to be / (root) that way linickx.com or linickx.com/blah can reference the cookie, and because it’s set to / the plugin can be used on any site !

To install:

  • Save root-cookie.txt in your plugins directory as root-cookie.php (Right Click - Save As)
  • From the Plugin Manager in the Dashboard, “Activate” the plugin
  • Log out, and log in again
  • Done

Now your cookie can be referenced from any custom code you may have written outside of your WordPress install directory !

nick

 

18 Responses to “Cookie Path Plugin For WordPress 2.0 (root Cookie)”

  1. Zach Garner says:

    This plugin sounds interesting, but for differnet purposes. Is it possible to modify the plugin to allow cookie sharing across multiple WP installs?

    I suppose that might sound a little wacky, but I’ve read a bit about people tring to find solutions like this. Making some minor changes in wp-settings.php can fix the user name/ password issue across multiple blogs, but each sub-blog still requires a login and stores its own cookie.

    In my case I’m breaking my WP blog up into sections covering distinctly different topics. This works great with WP, aside from the cookie issue because I get (I’m a music/art geek) seperate catagories, rss feeds and even slight (or total, but I’m shooting for consistency) theme alterations.

    Anyhow, when I quickly read over the description of your plugin I thought I’d found the solution, then I re-read it. :)

    Sorry to be so detailed, but this is something I’m keenly interested in.

  2. [NICK] says:

    Hi Zach, I think the problem you’re describing is down to browser security. As far as I know cookies are only allowed within their own domain, and people want to run different blogs like http://www.myblog.com or http://www.supergeek.net, so the cookie set by one site isn’t avilable to the other.

    By default the WordPress cookie is only avilable to the install path, so http://www.website.com/blog or http://www.install.com/wordpress , my plugin removes that limitation so that http://www.website.com/anything or http://www.install.com/something-else is able to access the http://www.website.com/blog or http://www.install.com/wordpress cookie: note access, if you want to use the cookie on another wordpress install I’d guess you’d have to change the auth_redirect function on the second blog.

    On my site I’ve changed the cookie so that my custom pages on the root of my domain can be authenticated by the wordpress cookie, if your blogs (or custom code) are blog1.domain.com and blog2.domain.com I think the COOKIE_DOMAIN constant in the plugin would need changing.

    If there’s a demand for cooke sharing I’ll take a look at it, so let me know how you get on :-D

  3. Pete says:

    Thanks for the plugin! This will allow me to run XDForum in a (fake, using apache rewrite mod) directory of its own and keep users logged in.

  4. Eric says:

    How about setting it up with different subdomain?

    i have it setup like:
    sub.domain.com/wordpress/
    http://www.domain.com/wodpress/

    They are two blogs sharing the same user/levels table different content. I just don’t know how to edit the cookie stuff,

  5. Zach Garner says:

    [NICK],
    It actually worked out great. I’m using your plugin with 6 seperate installations. I only had to make some minor changes to the cookie naming convention so they can share properly.

    I realize what I was doing was a little different but I was porting from Joomla and wanted to keep some of the CMS features but take advantage of WP. I’m very happy with the results.

    Thank you!

  6. [...] [LINICKX].com » Blog Archive (tags: wordpress plugin cookie login) [...]

  7. [...] root Cookie is a simple plugin that changes the authentication cookie’s path to /. It is useful if you use wordpress code outside of your wordpress installation directory. [...]

  8. [...] root Cookie ist ein einfaches Plugin, dass den Pfad zur Identifizierung via Cookie in / ändert. Sinnvoll, wenn man WordPress Code außerhalb des Installationsverzeichnis’ verwendet. [...]

  9. [...] root Cookie es un plugin sencillo que cambia la ruta del cookie de autenticación a /. Este es útil si utilizas código de Wordpress fuera del directorio de instalación de Wordpress. [...]

  10. [...] root Cookie is a simple plugin that changes the authentication cookie’s path to /. It is useful if you use wordpress code outside of your wordpress installation directory. [...]

  11. Hey - I installed your plugin and followed your directions, but I’m still not getting Vanilla to work with Wordpress. I can log into both WP and Vanilla with the same ID, but I can’t login to both at the same time. I know this is a cookie issue. Any help would be appreciated. Here is my original post describing my issue with links to my forum:

    http://lussumo.com/community/discussion/6132/cant-login-to-vanilla-after-integration-with-wordpress/

    Thanks!

  12. [NICK] says:

    Hi Gretchen,

    I’ve had a look at your site (and forum post) and I’m afraid my plug-in won’t help you, the wordpress cookie is “restricted” to where it is installed, for example on my site this is linickx.com/blog, but any directory below that can use the cookie, i.e. linickx.com/blog/post-name works. On my website the cookie simply strips off the /blog so I can use the cookie in my custom php. (e.g. linickx.com/random-dir)

    Correct me if I’m wrong, but it appears that you have installed wordpress in the root folder and vanilla in /forum , thus by default vanilla will already have access to the cookie.

    If you’re set on true site integration I would suggest you look at using bbpress, since it’s written by the same team you’ll get the integration you need, and some helpful support when it doesn’t work.

    hth !

  13. Chris Ward says:

    Did Eric’s question ever get answered? I’m also facing the same problem where I have two installations of Wordpress running, one on the domain home HumanEcologyForum.org, and the other in a subdomain events.HumanEcologyForum.org

    The subdomain is pulling the users information and authentication from the home domains DB, but the content is different.

    Do you know of a way to make it so I can have an integrated login using your plugin in this situation? It would be AWSOME! if I could. Right now i have to log in two times, once for each site, to do administration.

    Thanks!

  14. [NICK] says:

    Hi Chris,
    It doesn’t look like it did. According to the PHP reference .domain.com should work, try changing the COOKIE_DOMAIN constant by inserting something like define("COOKIE_DOMAIN", ".domain.com"); above the setcookie statements.
    hth,
    Nick

  15. Anna says:

    Just wanted to say: absolutely briljant plugin, thanx a million times!

  16. Hey, we just updated your code to work with WP 2.6, let us know if you’re still interested in this plugin or we could just start a new one.

  17. Nick says:

    Hi Scott,
    I’ll drop you an e-mail, I’d be happy to merge what you’ve done.
    rgds,
    Nick

 

Some other things that might interest you...

---