Magento and WordPress – Cookies on Both

This quickly covers being able to use Cookies outside of Magento that are set inside Magento.

I was working with another guy on a site that utilized both Magento and WordPress.  We kept the installs separate and just used the same styling on both to tie them together.  It worked nicely until we needed one bit of information in WordPress that we could not seemingly find a way to do.

I tried to do it with sessions but quickly ran into a directory tree problem because both directories were on the same level.

So I tried with cookies only to run into a similar problem.

I was finally able to get it working by making the cookie available across the domain with the following code:


setcookie("allebrum", $count, 0, "/", ".allebrum.com");

Then from WordPress I could call my cookie by using $_COOKIE[“allebrum”].

When setting the cookie the 4th parameter sets the cookie path to the root of the site, making it accessible outside the directory tree.

Advertisements

1 Comment (+add yours?)

  1. Chris
    Sep 16, 2010 @ 08:28:46

    Good solution.

    In magento where did you set this cookie. It can\’t be set in the phtml files so did you set it in the index.php?

    Chris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: