Page 1 of 1
Preventing Automated Registrations
Posted: Wed Jun 05, 2002 10:08 pm
by Cokeman
I was wondering if anyone has or has come across a script that would prevent automated registrations. A lot of the larger sites are now using this method where during signup a random code is generated on the fly and displayed as small graphic images. You would then enter what you see into a text box and complete the registration process.
Has anyone come across any PHP code for something like this?
Thanks!
Posted: Thu Jun 06, 2002 2:42 am
by MattF
The best way I think of doing it would be to assign each potential visitor a session ID and save it in a database along with a timestamp and a random code. Then they have to type the code in and if the code matches their session ID then they are allowed to register. If the user doesn't register and goes away then the timestamp can be used to delete old records that have not been used. What do you think of that?
Posted: Thu Jun 06, 2002 7:44 am
by volka
I have seen this on t-online SMS page but -sorry- no script yet.
a basic approach is
Code: Select all
<?php
function idImage()
{
if (!isset($_SESSIONї'code']))
$_SESSIONї'code'] = sprintf("%04d", rand(0,9999));
$img = @imagecreate (50, 20) or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($img, 200, 200, 200);
$text_color = imagecolorallocate ($img, 40, 40, 40);
imagestring($img, 5, 5, 3, $_SESSIONї'code'], $text_color);
header ("Content-type: image/png");
imagepng ($img);
}
function doRegister()
{
print('<html><body>your registration has been accepted<br>');
while(list($key,$value)=each($_POST))
print("$key : $value <br>");
print('</body></html>');
}
session_start();
if (strcmp($_SERVERї'QUERY_STRING'], 'id')==0)
idImage();
elseif(isset($_POSTї'register']))
{
if (!isset($_POSTї'code']) || !isset($_SESSIONї'code']) || strcmp($_SESSIONї'code'], $_POSTї'code']))
die('<html><body>code not accepted</body></html>');
else
{
doRegister();
unset($_SESSIONї'code']);
}
}
else {
?><html><body>
<form method="POST">
<table>
<tr><td>name:</td><td><input type="text" name="name" /></td></tr>
<tr><td>First name:</td><td><input type="text" name="fname" /></td></tr>
<tr><td>email:</td><td><input type="text" name="email" /></td></tr>
<tr><td>enter <img src="<?php print($_SERVERї'PHP_SELF']); ?>?id"/></td><td><input type="text" name="code" /></td></tr>
<tr><td><input type="submit" name="register"/></td><td></td></tr>
</table>
</form>
</body></html>
<?php } ?>