Blog |Follow Nick on Twitter| About

I've been wanting to do this for a while, this is the 1st in a planned short series of tutorials for my root cookie WordPress plugin.

I've decided to start with the purpose I wrote the plugin, then I'll move onto a couple of tutorial which answer some of the FAQs I get.

Before you start you need a working copy BLANK of WordPress, in a sub directory, with a url like
A BLANK copy is a fresh install, using the default theme and only my root-cookie plugin installed, remember after activating the plugin clear your browsers cookies.

Getting Started.
So you have a ready & waiting copy of WP, next create a directory called "my-scripts" or whatever you like, and in it create 1.php with the following contents:

<?php print_r($_COOKIE); ?>

Browse to and you'll get a blank white page with Array().
Next log into WordPress, and re-fresh 1.php and you should get something like....

Array ( [wordpress_xxxxxxxxxxxxxyyyyyyyyyyyyyy] => admin|1241455565|xxxxxxxxxxxxxyyyyyyyyyyyyyy [wordpress_logged_in_xxxxxxxxxxxxxyyyyyyyyyyyyyy] => admin|1241455565|xxxxxxxxxxxxxyyyyyyyyyyyyyy )

Done! You've just accessed WordPress's cookies :)

Now when I first started I had a very basic script which hid my Google adverts when I'm logged in, it's against Google's policies to click on your own adverts so to avoid accidents I wanted to hide them.

The following script is NOT secure, it doesn't check that you've logged into WordPress it simply checks that you a cookie set with the right username (which anyone can fake) but for my purpose this was fine, I had no issues with users faking cookies to get rid of the adverts*

<?php if (isset($_COOKIE["wordpress_logged_in_fxxxxxxxxxxxxxyyyyyyyyyyyyyy"])) { $cookie = $_COOKIE["wordpress_logged_in_xxxxxxxxxxxxxyyyyyyyyyyyyyy"]; $cookie_elements = explode('|', $cookie); if ($cookie_elements[0] == "admin") { echo "<h1>Hello admin!< </h1>"; } } ?>

Replace admin with whatever username your using and job done! Next time Accessing two WordPress installs with root-cookie :)

*this will not work now, as I do something different. :)


Nick Bettison ©