-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe.php
65 lines (51 loc) · 1.56 KB
/
subscribe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
if (!file_exists("fd-crm-20231028.csv")) {
$f = fopen("fd-crm-20231028.csv", "w");
$data = [
"EMail" => "EMail",
"Name" => "Name",
"Birthday" => "Birthday"
];
fputcsv($f, $data);
fclose($f);
}
if (isset($_POST['email'])) {
$email = $_POST['email'];
$name = isset($_POST['name']) ? $_POST['name'] : "";
$bday = isset($_POST['birthday']) ? $_POST['birthday'] : "";
$file = fopen("fd-crm-20231028.csv", "r");
if (!preg_match("/^[a-zA-Z0-9\s]+$/", $name)) {
$name = preg_replace("/\W+/", "", $name);
}
if (strlen($name) > 16) {
$name = substr($name, 0, 16);
}
if (strlen($bday) >= 10 && preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}/", $bday)) {
$bday = substr($bday, 0, 10);
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email address";
fclose($file);
exit();
}
while (($column = fgetcsv($file, 10000, ",")) !== FALSE) {
if ($column[0] == $email) {
echo "You are already subscribed to our newsletter. Redirecting to homepage in 3 seconds...";
header("refresh:3;url=index.php");
fclose($file);
exit();
}
}
$f = fopen("fd-crm-20231028.csv", "a");
fputs($f, "\n");
$data = [
"EMail" => $email,
"Name" => $name,
"Birthday" => $bday
];
fputcsv($f, $data);
fclose($f);
echo "You have been subscribed to our newsletter. Redirecting to homepage in 3 seconds...";
header("refresh:3;url=index.php");
}
?>