Reputation: 74219
I realize that this question has been asked many times, but I've yet to find a flatfile version.
I'm looking for a way to achieve the following in PHP or CGI-PERL, preferably PHP:
(confirmed_emails.txt for example).
One way that I've thought of, is some form of "opt-in" method.
Is this possible without SQL or a similar database?
Upvotes: 1
Views: 547
Reputation: 10732
I think you can probably manage this without storing anything, even in a text file.
When you generate the unique code that you're emailing to the user for confirmation, create it by hashing the email address that you're sending it to, and have the link of the format:
http://www.example.com/confirm.php?email=<emailaddress>&confirm=<hashedemail>
Then just re-hash the email address from the link against the hash in the link, and if they match, you've confirmed the email address.
(Though I'm very curious as to why you don't want to store it in a database - presumably you'll need to store the email addressed in one so you can do something useful with them?)
Upvotes: 1
Reputation: 5063
It's possible.
When writing the email to the temp_emails.txt file open it like such:
$f = fopen('temp_emails.txt', 'a+'); // open for read/write at end of file
fwrite($f, $email); // write the email to the file
fclose($f); // close it
// send new email
They get their link [email protected]
// first check if they already confirmed it
$file = file('confirmed_emails.txt');
if(!in_array($email, $file)){
// not in file
$f = fopen('confirmed_emails.txt', 'a+');
fwrite($f, $email);
fclose($f);
}else {
// already confirmed
}
Upvotes: 3