intial code commit
This commit is contained in:
parent
394936d013
commit
14a81a7425
1 changed files with 94 additions and 0 deletions
94
contactform.php
Normal file
94
contactform.php
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
<?php
|
||||||
|
// Form code for mail submissions
|
||||||
|
// For usage with hugo site
|
||||||
|
|
||||||
|
// Anti exploit code, not perfect but should throw a wrench into a bot's plan
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
class antibot {
|
||||||
|
|
||||||
|
private $passfail;
|
||||||
|
|
||||||
|
function __constructor(){
|
||||||
|
$passfail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fromtest() {
|
||||||
|
if ($_SERVER['HTTP_REFERER'] = "http://yourwebsite.com/contactus/"){
|
||||||
|
$passfail = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ratetest() {
|
||||||
|
if (!$_SESSION['last_submit']){
|
||||||
|
$_SESSION['last_submit'] = time(); // May not stick to a bot but doing it anyhow
|
||||||
|
$passfail = 2;
|
||||||
|
}else{
|
||||||
|
//print "Session found";
|
||||||
|
if (time()-$_SESSION['last_submit'] < 60){
|
||||||
|
// Purposefully not letting them know what the interval is
|
||||||
|
die('Error: Message not sent, rate limit hit. Please wait a few minutes and try again.');
|
||||||
|
$passfail = 0;
|
||||||
|
}else{
|
||||||
|
$_SESSION['last_submit'] = time();
|
||||||
|
$passfail = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function traptest() {
|
||||||
|
if($_POST['website']){
|
||||||
|
$passfail = 0;
|
||||||
|
}else{
|
||||||
|
$passfail = 3;
|
||||||
|
}
|
||||||
|
return $passfail;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function test_input($data) {
|
||||||
|
$data = trim($data);
|
||||||
|
$data = stripslashes($data);
|
||||||
|
$data = htmlspecialchars($data);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sndmsg($target) {
|
||||||
|
// First clean the data
|
||||||
|
$fname = $this->test_input($_POST["fname"]);
|
||||||
|
$lname = $this->test_input($_POST["lname"]);
|
||||||
|
$email = $this->test_input($_POST["email"]);
|
||||||
|
$comments = $this->test_input($_POST["comments"]);
|
||||||
|
// compile cleaned message
|
||||||
|
$msg = "From $fname Subject $lname email $email with message $comments";
|
||||||
|
mail($target,"Website Form Submission",$msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function do_tests(){
|
||||||
|
$this->fromtest();
|
||||||
|
$this->ratetest();
|
||||||
|
$result = $this->traptest();
|
||||||
|
if($result == 3) {
|
||||||
|
$this->sndmsg("you@yoursite.com");
|
||||||
|
return 3;
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$lcheck = new antibot();
|
||||||
|
|
||||||
|
$winner = $lcheck->do_tests();
|
||||||
|
|
||||||
|
if ($winner == 3){
|
||||||
|
echo "Form Submitted thank you!";
|
||||||
|
}else{
|
||||||
|
echo "Error: Send failed, please try again.";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue