Forum Moderators: coopster
I found an open source mailing list script which I am changing around a bit.
I have set it up so that when they type in their email it stores their email on a flatfile database as their email and hash with two pipes. Like so:
email¦¦efonasdgo8sehg0k
They are sent a link for confirmation. The link contains the md5 code under variable "id".
Now the subscribe page looks kinda like this:
<?php
$tmpinfo = file("tmp.txt");
$emailhash = $_GET["id"];
$emailemail = $_GET["email"];
foreach($tmpinfo as $key => $val)
{
$data[$key] = explode("¦¦", $val);
}
for($k = 0; $k < sizeof($tmpinfo); $k++)
{
$tmpemailfrontflatfile[$k][0];
$tmphashfromflatfile[$k][1];
}
$tmpemail = $tmpemailfromflatfile;
$tmphash = $tmphashfromflatfile;
if (($_GET["action"] == "add")&&($tmphash == $emailhash))
{
$fp = fopen("subscribers.txt", "r");
$file_text = fread($fp, 999999);
fclose($fp);
$subscribers = explode(",",$file_text);
foreach($subscribers as $subscriber)
{
if($subscriber == $_GET["email"])
{
$result = 1;
break;
}
else
{
$result = 0;
}
}
if($result == 1)
{
$msg = "<h3>Sorry, we cannot add you as... you already exist on this list...</h3>";
}
else
{
$fp = fopen("newsletter/data/subscribers.txt", "a+");
fwrite($fp, $_GET["email"] . ",");
fclose($fp);
$msg = "<h3>You have been added to the newsletter. Thanks!</h3>";
}
}
else {
die ('no');
}
$page="about"; include ("inc/files/header.php");?>
<!-- content -->
<div id="content"><?php echo "$msg";?></div>
<!-- // content -->
<?php include ("inc/files/footer.php");?>
The problem is that I am not sure it is looking up the email id and the tmp.txt id to match it. If it is, then it appears it doesn't do anything if they don't.
What I am aiming for is that if the email id hash is the same as the one stored for that particular email (under tmp.txt) tnen it adds them to the subscribers.txt file, otherwise it comes up with an error.
This is to stop people from just typing in the URL of the addition code.
Any ideas please?