HashCash refers to a 'proof of work' anti-spam measure originally proposed by Adam Beck in 1997. It was originally intended to fight e-mail spam, but the concept has been adapted for spam on Web based forms as well.
HashCash works by requiring the client (the user's computer) to spend a modest amount of CPU time computing a value. This value is then submitted to the server and checked with negligible work. Since spambots profit from their ability to send a great deal of spam in a short amount of time, requiring them to spend up to several seconds computing a value is a deal-breaker. A well balanced HashCash implementation requires a complicated enough calculation to make spamming unprofitable, but not to inconvenience human users.
<script language="Javascript" src="hashcash.php"></script>
id="checkForm"
<form action="submit.php" id="checkForm" method="post">
<body onload="find_salt('checkForm');">
<?php
session_start();
$hex_key = "2:".$_SERVER["REMOTE_ADDR"].':'.$_SESSION["request_time"].':'.$_POST['hashcash'];
$pattern = '/^0{'.$_SESSION['level'].'}/';
if ( preg_match($pattern, sha1($hex_key) ) ) {
} else {
print "An error has occured. Please go back, refresh the form page and please try again.";
} unset ($_SESSION['request_time']);
?>
You are all set! Whenever a user comes to your form, their system will automatically start calculating the secure HashCode value, which makes spamming impossible without causing inconveniences for human users.
In some instances, you might want to protect more than one form on your Web page with the HashCash script. This script has the flexibility to fulfill more than one form with the following modifications.
<form action="submit.php" id="checkForm2" method="post">
<body onload="find_salt('checkForm');
find_salt('checkForm2');">
You can have as many scripts as you would like just by appending additions to the code.
To further protect your form, you may also add additional Javascripts to check and validate required fields. You can easily customize it to match your unique form.
<script language="Javascript" src="required_fields.js"></script>
<script language="Javascript" src="emailCheck.js"></script>
You are done! Whenever a user forgets to fill out a required field, an alert box will appear to remind them which fields they missed. The form will not submit unless all the required fields are filled out.
ITS Web Account Application Form
Departmental Web Server Registration
Request to add/update a hyperlink to my page on the main URI Web site.
What if the Webmaster made a mistake!
Subscribe to the URI Web Publishing Blog for latest news, tips, resources and tools related to web technologies.
Subscribe to URIWEB-L Listserv to keep informed of ideas on web-related issues on campus.