Using cookies when developing locally with MAMP

While working on my record label site I’m using the Last Viewed Posts plugin to grab and display the user’s last 8 viewed posts. This plugin sets a cookie to keep track of what posts/pages have been viewed during the session. It works great and you can see it in action on any of the release pages on the Vizual Records site.

In an earlier post I mentioned SyncDB which is an invaluable script if you develop WordPress locally with MAMP. Just to reiterate how cool this is, if you’re working locally on a site, you can create all your posts, upload content and do whatever you need to do on your local install. Once you’re ready, run SyncDB from the terminal while in your project folder and your local and remote db is backed up, the updated local db is uploaded to your remote web server, then it runs the Interconnectit search and replace db script replacing your local URL with your remote URLs automagically. Then, it syncs your /wp-content/uploads folder. All this in about 20 seconds. Donezos. Open up your site on the web and your new content is there.

I bring up SyncDB because after putting it off for a while I finally moved vizualrecords.com back down to a fully local install and SyncDB made this super easy. Almost immediately after this was done I noticed that the Last Viewed Posts was not displaying anything. I checked the cookies in several browsers and the “WP-LastViewedPosts” cookie was seemingly there but nothing was being displayed. Echoing out the cookie showed nothing as well. What was going on?

It turns out that the cookie spec requires that the domain have at least two words separated by a period. So if your local site is using something like “localhost” or “vizual2014” the cookie won’t be set.

The solution is simple and I found it on Stack Exchange:

Just use a dot in your local site url in MAMP (this applies to LAMP or other setups as well).

So instead of using vizual2014, I switched it to vizual.local, then ran the Interconnectit script manually and boom! Cookies were now being set and I was on my merry way.

See All Posts →

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">