// Simple honeypot for an HTML form using PHP
<?php
//check if form was sent
if($_POST){
$to = 'some@email.com';
$subject = 'Testing HoneyPot';
$header = "From: $name <$name>";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//honey pot field
$honeypot = $_POST['firstname'];
//check if the honeypot field is filled out. If not, send a mail.
if( ! empty( $honeypot ) ){
return; //you may add code here to echo an error etc.
}else{
mail( $to, $subject, $message, $header );
}
}
?>
<html>
<head>
<title>HoneyPot for HTML Form Example</title>
<style>
.hide-robot{
display:none;
}
</style>
</head>
<body>
<form method="post" action="#my-form" id="my-form">
<!-- Create fields for the honeypot -->
<input name="firstname" type="text" id="firstname" class="hide-robot">
<!-- honeypot fields end -->
<input name="name" type="text" id="name" placeholder="Name" required><br>
<input name="email" type="email" id="email" placeholder="Email" required><br>
<textarea name="message" id="message" placeholder="Enter your message here" required></textarea><br>
<input type="submit">
</form>
</body>
</html>
출처 : https://gist.github.com/andrewlimaza/958826feac907114a57462bfc8d535ff
'웹 개발 이야기 > php' 카테고리의 다른 글
[PHP] 현재 보고있는 화면 캡쳐 후, 다운로드 / 인쇄 (0) | 2023.03.16 |
---|---|
[PHP] AWS S3 Bucket에 파일 업로드 (0) | 2023.03.16 |
[PHP] calendar_basic (0) | 2023.03.09 |
[PHP] 인스타그램 피드 가져오기 (Rapid API 이용) (0) | 2023.03.09 |
[PHP] 그누보드 자동 로그인 풀릴 때 (0) | 2023.03.09 |
댓글