si-blog

Comment cookie factory open for business

Posted Mar 26, 2004 in PHP.

After a little prodding, I am now giving you the chance to store your name, email address, and URI as cookies when you post a comment (if so desired). The cookies are set to expire in one year, but if anyone thinks that is inappropriate, I'll change it.

Actually, this is my first foray into messing with cookies. Up until now, I have never found a need for them. At first, I started writing a JavaScript function to do it for me, but then it dawned on me that it was probably easier to do it in PHP, since I was already using it for everything. PHP makes it very easy:

if(isset($HTTP_POST_VARS['bake_cookie'])) {
	setcookie("user_name", $HTTP_POST_VARS['user_name'], time()+31536000, "/", "jessey.net", 0);
	setcookie("user_email", $HTTP_POST_VARS['user_email'], time()+31536000, "/", "jessey.net", 0);
	setcookie("user_url", $HTTP_POST_VARS['user_url'], time()+31536000, "/", "jessey.net", 0);
}

I don't know if this is the most efficient way of doing it, but it works very well. By the way, I am using $HTTP_POST_VARS because I have been used to writing PHP for clients who have register_globals set to OFF, which is probably a good idea anyway.

Comments

  1. Gravatar

    Hurray!! This is excellent, Simon. A good thing about this, among others, is that lazy people --such as myself-- will find it easier to come and just start babbling. Some might disagree, but that's babble for a different topic... :-)

    Posted by David Collantes on Mar 26, 2004.

  2. Gravatar

    The part where the snipet of code shows is not on a text box on this screen (comment entry) and overlaps with your side (right) column. At least it shows like that on Win IE6SP2RC1.

    Posted by David Collantes on Mar 27, 2004.

  3. Gravatar

    Thank you, David. I am aware of the problem - I haven't found the time to convert older pages to the new layout, which features a <pre> element styled with the CSS overflow property (which creates scrollbars when needed). I will fix that over the next few days.

    Posted by Simon Jessey on Mar 27, 2004.

  4. Gravatar

    Hello ;-)

    Update: This is comment spam. Why can't you people just fuck off and leave us bloggers alone? Your email and URL have been removed.

    Posted by Soma on May 28, 2004.