I changed your script a little bit to be able to test it, without changing the logic of it, and it works just fine. Are you sure the script you posted is the same you got running on your site?
This is the (modified) script I tested:
Codice PHP:
<?php
$listfile = "maillist.txt";
function checkmail ($email)
{
global $listfile;
$fd = fopen ($listfile, "r");
$contents = fread ($fd, filesize ($listfile));
fclose ($fd);
if (@stristr($contents,$email))
$valid = "invalid";
if (eregi("^[_\.0-9a-z-]+@([0-9a-z][-0-9a-z\.]+)\.([a-z]{2,3}$)", $email) && !isset($valid))
$valid = "valid";
else
$valid = "invalid";
return $valid;
}
if ($action == "subscribe" && isset($email))
{
$valid = checkmail($email);
if ($valid == "valid")
{
$fp = fopen($listfile, 'a+');
flock($fp,2);
fwrite($fp,"".strtolower($email).",");
fclose($fp);
}
}
elseif ($action == "unsubscribe" && isset($email))
{
$fd = fopen ($listfile, "r");
$contents = fread ($fd, filesize ($listfile));
fclose ($fd);
$allpeople = "";
$entries = explode(",",$contents);
for($i=0;$i<count($entries);$i++)
{
if (strtolower($email) == strtolower($entries[$i]))
$found = "yes";
elseif ($entries[$i] != "")
$allpeople .= "".$entries[$i].",";
}
if ($found == "yes")
{
$fp = fopen($listfile, 'w');
fwrite($fp,$allpeople);
fclose($fp);
}
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
Indirizzi iscritti:<br>
<br>
<?php
$fd = fopen ($listfile, "r");
$contents = fread ($fd, filesize ($listfile));
fclose ($fd);
$entries = explode(",",$contents);
for($i=0;$i<count($entries);$i++)
{
echo $entries[$i]."<br>\n";
}
?>
<br>
<form method=post action="index.php">
<div class="posizione"><span lang="it">Iscriviti alla newsletter</span><br>
<span lang="it">Inserisci il tuo indirizzo
e-mail:</span><br>
<span lang="it"><input type="name" name="email"><br>
<input type="radio" name="action" value="subscribe" checked>Iscrivi
<input type="radio" name="action" value="unsubscribe">Rimuovi<br>
</span>
<span lang="it">
<input type=submit value=Invia></span><br>
</form>
</body>
</html>