get_addresses.php
/**
* Variables
*/
$addlist = 'addlist.csv'; // Filename with subscribers: please change for security purpose
$removelist = 'deletelist.csv'; // Filename with unsubscribers: please change for security purpose
$pass = 'qwerty'; // Access password: change for security purpose
$form_type = '2'; // Type of form: 1 - only email, 2 - email and name
/**
*
*/
$key_url = $_SERVER['REQUEST_URI'];
if (strpos($key_url,"?") !== false) {
$get_add = "&";
$key_url = explode('key_status=',$key_url);
$key_url = $key_url[0];
} else {
$get_add = "?";
}
if (@isset($_GET['pass']) && $_GET['pass'] != '' && @$_GET['pass'] == md5($pass)){
if (@isset($_GET['add'])){
read_output_clear_file ($addlist);
} else
if (@isset($_GET['remove'])){
read_output_clear_file ($removelist);
} else echo 'ERROPER';
} else if (isset($_GET['pass']) && $_GET['pass'] != '') echo 'ERRPASS';
function read_output_clear_file ($filename){
$f = fopen($filename, "r");
print(fread($f, filesize($filename)));
fclose($f);
$f = fopen($filename, "w+");
fclose($f);
}
function check_record_exist ($filename, $email, $type = 1){
if (file_exists($filename)){
$keys = file($filename);
$kcnt = count($keys);
$exist = 0;
for ($i = 0; $i < $kcnt; $i++){
if ($type == 1){
if ($keys[$i] == "$email\n") {
$exist = 1;
break;
}
} else {
$data = split(";", $keys[$i]);
if ($data[0] == "$email") {
$exist = 1;
break;
}
}
}
if ($exist == 0) return $exist;
else return ($i+1);
} else return 0;
}
function add_record ($filename, $email, $name = ''){
$f = fopen($filename, "a+");
if ($name == '') fwrite($f, "$email\n");
else fwrite($f, "$email;$name\n");
fclose($f);
}
function delete_line_from_file ($filename, $line){
if (file_exists($filename)){
$data=file($filename);
$f=fopen($filename,'w');
$size=count($data);
for ($i = 0; $i < $size; $i++)
if ($i != $line) fputs($f,$data[$i]);
fclose($f);
}
}
?>
form.php
include_once("get_addresses.php");
@$email = strtolower(trim($_POST['email']));
@$name = trim($_POST['name']);
@$type = $_POST['type'];
if (isset($_POST) && count($_POST) != 0){
if (@isset($email) && @$email != ''){
if (@isset($type)){
switch ($type){
case '1': {
$line = check_record_exist ($removelist, $email, $form_type);
if ($line){
$line--;
delete_line_from_file ($removelist, $line);
}
if (!check_record_exist ($addlist, $email, $form_type)){
add_record ($addlist, $email, $name);
header('Location: '.$key_url.$get_add.'result=1');
exit();
} else {
header('Location: '.$key_url.$get_add.'result=3');
exit();
}
}
case '0': {
$line = check_record_exist ($addlist, $email, $form_type);
if ($line){
$line--;
delete_line_from_file ($addlist, $line);
}
if (!check_record_exist ($removelist, $email, $form_type)){
add_record ($removelist, $email, $name);
header('Location: '.$key_url.$get_add.'result=2');
exit();
} else {
header('Location: '.$key_url.$get_add.'result=4');
exit();
}
}
}
} else echo 'Please specify type of action';
} else echo 'Please enter e-mail address';
}
if (isset($_GET['result'])) {
switch ($_GET['result']){
case '1': echo 'You have successfully subscribed'; break;
case '2': echo 'You have successfully unsubscribed'; break;
case '3': echo 'You are already subscribed'; break;
case '4': echo 'You are already unsubscribed'; break;
}
} else { ?>
} ?>
Your testimonial has been successfully submitted
, editors will review and publish it
Your email has been successfully submitted
Your email has been successfully submitted
Your comment has been successfully submitted
An unexpected error has occurred please try again