Apache RewriteRule : Set a session cookie on localhost

Here are the 2  (often left out) requirements to set a cookie using httpd’s rewrite rule (mod_rewrite), while working on localhost:

  1. Use the IP 127.0.0.1 instead of localhost/machine-name as the domain; e.g. [CO=someCookie:someValue:127.0.0.1:2:/], which says create a cookie “someCookie” with value “someValue” for the domain “127.0.0.1” having a life time of 2 mins, for any path in the domain (path=/). (Obviously you will have to run the application with this value in the URL)
  2. To make a session cookie, limit the flag statement to just three attributes: name, value and domain. e.g [CO=someCookie:someValue:127.0.0.1] – Any further settings, apache writes an” expires” attribute for the set-cookie header, which makes the cookie a persistent one (not really persistent, as the expires value set is the current server time – so you don’t even get to see your cookie!)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

46,675 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>