Archive for the ‘setting cookies through htaccess’ Category

cookies

Lastly, a quick word about cookies. While it’s easy enough to set cookies in .htaccess without any mod_rewrite..

create a cookie called “example-cookie”, and set its value to “true”…..
Header set Set-Cookie “example-cookie=true”….

..you will need it to read the cookie information back again, and “do stuff” with it. It’s easy. For example, to check if the above cookie exists and has the correct value set, we could simply do..

check for that same cookie + value..
Options + FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_COOKIE} !my-tools=true
RewriteRule .* /err/401.php

..which could easily form the basis of a simple authentication system. As with any RewriteCond, you can get pretty complex, checking multiple cookies, utilizing regexp and more, but that’s enough to get you started.

Hope you will enjoy this…… 🙂