Skip to content

Instantly share code, notes, and snippets.

@icyleaf
Created March 9, 2012 02:35
Show Gist options
  • Save icyleaf/2004690 to your computer and use it in GitHub Desktop.
Save icyleaf/2004690 to your computer and use it in GitHub Desktop.
Anti SPAM by javascipt + php
<?php
if ($_POST['random'] != $_POST['nospam'])
{
// spam
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<form method="POST" action="post.php">
<input id="random" name="random" type="hidden" value="{{random}}" />
<input id="nospam" name="nospam" type="hidden" value="0" />
Username: <input type="text" name="username" /><br />
Email: <input type="text" name="email" /><br />
Website: <input type="text" name="website" /><br />
<textarea name="content" /></textarea>
<input type="submit" value="Post it!" /><br />
</form>
</body>
<script type="text/javascript">
function anti_spam(source, target)
{
$(document).ready(function(){
var s_input = $('#'+source);
var t_input = $('#'+target);
$('form').bind('submit', function(){
t_input.val(s_input.val());
});
});
}
anti_spam('random', 'nospam');
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment