Log in

View Full Version : Unsubscribe Link



Schmoopy
01-10-2009, 06:50 PM
Wondering how to this, after subscribing to a newsletter - I need some way to authenticate what the user's email is and then delete them from the database, anyone know a way to do this?

Somehow taking their email address from the page they last visited?

Thanks,

Jack.

bluewalrus
01-10-2009, 06:59 PM
Yeah are you trying to make a mailing list? I made a simple thing you can go through of here: http://www.dynamicdrive.com/forums/showthread.php?t=40161 If you dont want the whole thing the leave.php (i think) has how to remove one email address might need a few modifications but that basics.

Schmoopy
01-10-2009, 07:28 PM
Ah right, that's a nice compilation, but using this method means anyone can delete any other person's email from the list doesn't it? Or am I wrong?

Edit: Maybe it could be done with cookies that hold the unique id of the person... but people can still delete them =/

bluewalrus
01-10-2009, 08:02 PM
Well yea but I find the chances are really low though that someone would try to find the proper username and domain to get someone off a mailing list from a specific domain. You could set up an additional parameter like a unique ID with each that attaches after the username and is removed before it sends. So it would only be on when they join or want to leave. You'd have to send them an email to let them know that ID though or you could try your cookie idea as well but I don't know how to do that one.

Schmoopy
01-10-2009, 08:53 PM
Yea, well with the cookie it would work with the same ID sort of thing and when they unsubscribe the PHP looks at the ID in the cookie and then gets the corresponding email, just cookies can be deleted at any time so it isn't exactly fool proof.

Edit: Probably just easiest to go with the simple way, I mean you've got to be pretty bored if you're going to try and guess emails that are on the list already.

Not like it's a big company either.

bluewalrus
01-10-2009, 09:19 PM
This is only an idea I haven't test this and you'd need to remake the join form to get passwords and write that with the username to another text file where they are joined together...
(this is not a secure method at all however. You should randomize the text file name and not allow directory listings)


$username = $_POST['leavethepageemail'];
$password = $_POST['password'];
$myotherfile = "SSeCuRe@976535.txt";
$fh = fopen($myotherfile, 'r');
$securedata = fread($fh, 20000000);
fclose($fh);
$getout = str_replace($username . $password, "", $myotherfile);
$checkthat = str_replace($username , "", $myotherfile);
$checkthis = str_replace($password , "", $myotherfile);
if ($checkthat . $checkthis == $getout) {
$leaving = $username;
$myfile = "addresses.txt";
$fh = fopen($myfile, 'r');
$thedata = fread($fh, 20000000);
fclose($fh);
$leaving = $leaving . ', ';
$olddate = $thedata;
$remove = str_replace('Bcc: ' . $leaving, "", $thedata);
$file = "addresses.txt";
$newdata = $thedata;
$handle = fopen($file, 'w');
fwrite($handle, $remove);
fclose($handle);
if ($olddata <> $newdata) {
die ('You have successfully been removed from the mailing list.</body></html>');
}
else
{
die ('There was an error removing your email address from the mailing list please re-enter your email address. If the problem continues please contact the adminastrator.</body></html>');
}
}
else
{
die ('Your username or password were not found please try again.');
}


Oh you'd also want to write it so the username and password leave the secure text file as well

Schmoopy
01-10-2009, 09:41 PM
Thanks for that, but I think I'm going to just stick with the bog standard newsletter system ;)