Modifying my website to allow anonymous comments

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2009-03-12T05:13:04Z Indexed on 2010/04/27 2:03 UTC
Read the original article Hit count: 349

I write the code for my own website as an educational/fun exercise. Right now part of the website is a blog (like every other site out there :-/) which supports the usual basic blog features, including commenting on posts. But I only have comments enabled for logged-in users; I want to alter the code to allow anonymous comments - that is, I want to allow people to post comments without first creating a user account on my site, although there will still be some sort of authentication involved to prevent spam.

Question: what information should I save for anonymous comments? I'm thinking at least display name and email address (for displaying a Gravatar), and probably website URL because I eventually want to accept OpenID as well, but would anything else make sense?

Other question: how should I modify the database to store this information? The schema I have for the comment table is currently

comment_id       smallint(5)       // The unique comment ID
post_id          smallint(5)       // The ID of the post the comment was made on
user_id          smallint(5)       // The ID of the user account who made the comment
comment_subject  varchar(128)
comment_date     timestamp
comment_text     text

Should I add additional fields for name, email address, etc. to the comment table? (seems like a bad idea) Create a new "anonymous users" table? (and if so, how to keep anonymous user ids from conflicting with regular user ids) Or create fake user accounts for anonymous users in my existing users table?

Part of what's making this tricky is that if someone tries to post an anonymous comment using an email address (or OpenID) that's already associated with an account on my site, I'd like to catch that and prompt them to log in.

© Stack Overflow or respective owner

Related posts about database

Related posts about database-design