-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
120 lines (84 loc) · 3.14 KB
/
index.php
File metadata and controls
120 lines (84 loc) · 3.14 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
$errors = [];
$count_errors = 0;
// List of the words you want to block
$spam_words =
["http", "www", ".com", ".mx", ".org",
".net", ".co.uk",
".jp", ".ch", ".info", ".me",
".mobi", ".us", ".biz", ".ca",
".ws", ".ag",".com.co", ".net.co",
".com.ag", ".net.ag", ".it", ".fr",
".tv", ".am", ".asia", ".at", ".be",
".cc", ".de", ".es", ".com.es", ".eu",
".fm", ".in", ".tk", ".com.mx", ".nl",
".nu", ".tw", ".vg", "sex", "porn", "fuck",
"buy", "dating", "viagra", "money", "dollars",
"payment", "website", "games", "toys", "poker",
"cheap", "href","nude","cam","penis","pills",
"sale","cheapest", "script",'Mod', 'Owner',
'Mawd', 'M0d', '0wner','090','080','081','070','
091','0-','+','80','81','70','91','dot','f*ck',
'bitch','ww','cum','hacker','pussy', '<','>'
];
function is_blank($value) {
return !isset($value) || trim($value) === '';
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'):
// print_r($_POST);
// die();
$comment = $_POST['comment']; // This should be coming from a post request
$comment_str = (string)$comment;
$new_input = str_replace(' ', '', strtolower($comment_str));
if(!is_blank($comment)){
foreach($spam_words as $item) {
if (strpos($new_input, strtolower($item)) !== false) {
$errors[] = $item;
}
}
}
$count_errors = count($errors);
if ($count_errors >= 1) {
$user_spamwords = implode(",", $errors); // This are the lists of spam words inputted by the user
}else{
//Save the post or comment to the database
print "<script> alert('Saved') </script>";
}
endif;
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Form Validation!</title>
</head>
<body>
<div class="container">
<form action="" method="post">
<div class="card mt-5">
<div class="card-body">
<?php if ($count_errors >= 1): ?>
<div class="alert alert-danger" role="alert">
<small>You entered some forbidden words <?php print $user_spamwords; ?></small>
</div>
<?php endif; ?>
<div class="form-group">
<div class="mb-3">
<h5 class="text-info mb-2">Spam Word Checker.</h5>
<label for="exampleFormControlTextarea1" class="form-label">Comment</label>
<textarea name="comment" class="form-control" id="exampleFormControlTextarea1" rows="3" required></textarea>
</div>
</div>
<button type="submit" class="btn btn-success">Post</button>
</div>
</div>
</form>
</div>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>