How do I write a cron job script for verified act emails & lost passwords
timer?
How do I write a cron for verified act emails & lost passwords timer?
I'm using apache on Linux server with mysql database and php code. In the
database, besides the
usual fields for an account, I have verified(a boolean that is 1 for yes
and 0 for no), act_key
(varchar(50) for sending an email to users with link to special pages for
verifying there email
or if they forgot their password), time(datetime) and temp(boolean that is
1 for forgot password
or 0 for not).
When a user creates an account, I set the verified in the new act to zero,
time=current date &
time, temp=0 and generate act_key that I send in email to them. If they
try to login and there act is
not verified then they can't get in. If they click the link and go to a
certain page within an
hour I set verified to one and they can login. If they clink on the link
after the one hour
then I tell them that the key is invalid and there account was deleted and
to make a new one.
If a user forgets their password, they go to this page where they enter
their email and if the
email matches a record in the database I set temp=1 and time=current date
& time. I tell user
that I sent out email regardless. If they clink this new link it goes to a
page and if its less
then an hour I make them reset there password and temp is set back to
zero. If they click on
the link after the hour, I tell them the key is invalid. After one hour
temp is set back to
zero.
They can't use forgot password page if there account is unverified and if
they forgot or don't
have access to email for their account I them them too bad have to make
new act.
The verification process was working fine until I added the time variable
into the equation. I
never really got the forgot password part working.
I know I need to setup a cron job to do two things every hour:
delete accounts were verified=0 and it's been more than an hour since
created that act.
update accounts where temp=1 and it's been more than an hour since sent
out forgot password
email
My main questions are:
Am I using the correct datatype in my database for the time field? And if
not which should I use?
How do I set the time variable in the process register and forgot
pages?$time = getdate(); maybe, the default is null? $time is the variable
i'm using to insert into dB record for time field.
How do I make the cron script? I'm using godaddy, do I just point the cron
control to this php file and if so is this the code I need?
//connect to cron
/web/cgi-bin/php5 -f "$HOME/html/hourly.php";
//connect to dB
include 'db_connect.php';
//delete any unverified email act records that are more than 1 hour old
DELETE from members WHERE verified == 0 & time + 1 > NOW()
//make temp=0 on any record where temp is 1 for more than an hour
UPDATE members SET temp=0 WHERE temp == 1 & time + 1 > NOW()
mysqli_close($mysqli);
Does any of my overall method sound fundamentally flawed?
PLease thank you in advance.
No comments:
Post a Comment