Recently I responded to a question on how to make a Views Filter respond to a Cookie value. Put another way — if I have a View and I want to save off a filter value; how can I populate the filter criteria without having to submit the $exposed_form first. How can Views remember the value from a returning visitor?
The nice thing about this task is that Views provides a mechanism for you to do this from the Views Administration UI. This is true for essentially Drupal 6/7 and Views 2 or 3 at the time of this writing.
The concept is to use a Views Contextual Filter (D7 jargon) or a Views Argument (D6 jargon). The terminology here is slightly different between Views versions — but the UI choices are very similar. The following steps are for a Drupal 7 solution:
Then we configure the filter to pull a value from the URL. If none is provided we define how to find the value via PHP code. This is the secret to pulling the value from a $_COOKIE value.
Now the View works as if the filter was applied magically from nowhere!
You’ll note I didn’t cover how the value was stored in the cookie in the first place!? Cookies, can be stored from many many different places and occasions. The cookie key/value pair need simply be stored for the correct domain and your website will have access to it.