Forum Moderators: coopster
<?php
$subscribe = $_GET['subscribe'];
$unsubscribe = $_GET['unsubscribe'];
$address = $_POST['address'];
if ($subscribe = "subscribe")
{
if (ereg('^[a-zA-Z0-9 \._\-]+@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]+$', $address))
{
echo ("<HTML><BODY>Thank you for joining.</BODY></HTML>");
}
else
{
echo ("<HTML><BODY><b>$address</b> not a valid email address. Please try again.</BODY></HTML>");
}
if(file_exists("email_list.txt"))
{
$newfile = fopen("email_list.txt", "r");
while(!feof($newfile))
{
$duplicate = fgetss($newfile, 255);
if(eregi("$address", $duplicate))
{
echo ("<HTML><BODY><b>$address</b> is already in the database.</BODY></HTML>");
fclose($newfile);
exit;
}
}
fclose($newfile);
$addemail = fopen("email_list.txt", "a");
fputs($addemail, "$address\n");
fclose($addemail);
}
else
{
$newfile = fopen("email_list.txt", "a");
fputs($newfile, "$address\n");
fclose($newfile);
}
if ($unsubscribe = "unsubscribe")
{
$emails = file("email_list.txt");
for($index = 0; $index < count($emails); $index++)
{
if(ereg("$unsubscribe", $emails[$index]))
{
$emails[$index] = "";
$thefile = fopen("email_list.txt", "w");
for($newindex = 0; $newindex <count($emails); $newindex++)
{
if($emails[$newindex]!= "")
{
fputs($thefile, "$emails[$newindex]");
}
}
fclose($thefile);
echo("<HTML><BODY><b>$address</b> has successfully been removed from the database.</BODY></HTML>");
}
}
}
}
?>
That's quite a mouthful ;) Let's start with first things first ... unsubscribe.
In your code you are assigning a value again to the $unsubscribe variable, not comparing it. So at the top of your code you are getting the value of the GET variable named 'unsubscribe' and assigning it to the variable '$unsubscribe'.
$unsubscribe = $_GET['unsubscribe'];
if ($unsubscribe = "unsubscribe")
if ($unsubscribe == "unsubscribe")