[nycphp-talk] Email Signup Script
David Mintz
dmintz at davidmintz.org
Mon Aug 30 16:21:16 EDT 2004
On Mon, 30 Aug 2004, Joseph Crawford Jr. wrote:
> this would be simple to create read up on the mail() function and also read
> up on the $_GET variables
>
> very very easy to make this script.
But for the benefit of the newbies it would be helpful to provide an
outline in pseudo-code and leave the rest as a proverbial exercise for the
reader. I've done similar stuff but never actually done this exact task.
Here's how I might go about it; feedback is welcome.
(1) create a MySQL table with fields id, email, is_confirmed etc. Make
email a unique index. Make a varchar(32) column called conf_code for
holding an md5 hash of the email. make is_confirmed an unsigned tinyint
default 0.
(2) the signup script:
if it's the first pass, draw the form.
if the form is POSTed, validate.
If it's invalid, display error message, redraw.
otherwise: insert into your_table set email='$their_email',
conf_code=md5('$their_email');
send email to $their_email saying thank you, please go to
http://yoursite.com/confirm.php?conf_code= . md5($their_email) to confirm
your address;
redirect to success page that says, thanks, please go check your inbox.
(3) the confirmation script:
if there are no GET parameters, display a form prompting them for the
confirmation code. if there is a GET parameter conf_code,
select count(*) from your_table where conf_code ='$their_conf_code'
if count is 1, update your_table set is_confirmed = 1 where conf_code
= '$their_conf_code' and say thank you.
otherwise, say sorry...
---
David Mintz
http://davidmintz.org/
"Anybody else got a problem with Webistics?" -- Sopranos 24:17
More information about the talk
mailing list