Admin@mbox3.magellan-net.de
alina@yourmx.de
bm@schweinischer-bote.de
boris@cosmeta.de
boss@dan2n.de
btiggemann@mbox3.magellan-net.de
catcher009@blacknbeauty.de
Christopher_Zantopp@web.de
dok123@discardmail.com
dominik.keilbach@rocketmail.com
dominik2712@web.de
einkauf@dan2n.de
elke@kunesch.eu
erik_burgbacher_bi17l4lo@send.electronicmailfor.me.uk
feedme@die-bauer.de
feedme@dog-net.org
feedme@drakensang.de-web.cc
feedme@kraffner.de
feedme@schlaegel.it
feedme@sql-kunesch.de
feedme@wipeout6.de
fetcher@open-host.de
frank@spiracyworld.co.uk
getspam@schlaegel-online.de
harun-ali@web.de
iCollectGarbage@gmx.de
ifyoudone@r0ckt.de
ifyyou@r0ckt.de
info@die-bauer.de
info@mbox3.magellan-net.de
info@r0ckt.de
info@rbcms.de
john.deer@spamreducer.eu
john@cannedmeat.elementfx.com
k.tramm@xspin.de
Karl-Heinz.Becher@gmx.de
Kevin.Becaud@bio-muesli.info
kickers88@live.de
knuddels119k@yahoo.de
loremiosumsitdoloramet@yahoo.de
loremiosumsitdoloramet@yahoo.de
lotharwalter@ymail.com
luna@r0ckt.de
matz0302oyqp@domut.de
mgoessel@gmx.net
michael.k@drakensang.de-web.cc
michael.k@drakensang.de-web.cc
michael.k@sql-kunesch.de
michaknopf@googlemail.com
mk@r0ckt.de
msneijder@mbox3.magellan-net.de
nasti_mkorsa@sql-kunesch.de
newcyborg@gmx.net
schlucks@gmx.net
schwarz@die-bauer.de
service@mbox3.magellan-net.de
sp4mf4ng@j-schmitz.net
spam@teh1.de
spamcatcher@spamtrap.dtdns.net
spamela@spamschlucker.org
spamhog.ihatespam@gmail.com
spamlearn@schlarb-it.de
spamlearn@schlarb-it.de
spamtarget@junge-piraten.de
spamtrap@r0ckt.de
spamtrap@sprachdidaktik.org
spoof@dog-net.org
stephan@spamschlucker.org
support@mbox3.magellan-net.de
thanks@marvin-webservice.net
trap.mitschutz@sprachdidaktik.org
trap@sprachdidakt.de
trap@sprachdidaktik.org
trep@marvin-webservice.net
unwanted@shadowpage.de
vertrieb@dan2n.de
wb@munzinger.de
willmehr@drakensang.de-web.cc
willmehr@drakensang.de-web.cc
willmehr@wipeout6.de
wir@dragoncrew.de
xkbzy@grossermist.de
a Image

Today i created a new - even better - ৺captcha version for php.

The behavior is same as known from the old version - but now there are additional features:

  • generic image size
  • generic backgrounds (randomly selected, random Area if "bigger" thtn ৺captcha)
  • generic fonts (real TFFs, randomly selected)
  • generic chars (to prevent 0 o O - issues)
  • generic font size


The usage of the ৺captcha is quit simple in usage:

just include it as an Image does all the magic. If you like to , you can simple use Javascript!
to create new images on demand.

The generated ৺Captcha-Code is saved into the users current seession. so you just need to compare
the build hash of passed value, with the one stored in the session - and you got it ;-)

Here some examples of created images. (remember the generic backgrounds and fonts):

Another Pic
no title available
Another Pic
no title available
Another Pic
no title available
Another Pic
no title available
Another Pic
no title available
Another Pic
no title available
Another Pic
no title available



Here's the Source Code of the Project. you simple need to copy it to a file, called "captcha.php",
and create a directory called "captcha", where you put in your bgs and Tiffs.

In this Version, the script will use all PNGs and TTFs in that folder automatically.

The Capture is saved to

  1.  
  2. $_SESSION["Captcha"]
  3.  


With defined Salt as Pre- and Suffix.

  1.  
  2. <?php
  3. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  4. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') .' GMT');
  5. header('Pragma: no-cache');
  6. header('Cache-Control: no-store, no-cache, max-age=0, must-revalidate');
  7.  
  8. //generate a simple captcha.
  9. //i=l=I
  10. //0=o=O
  11. unset($_SESSION["Captcha"]);
  12.  
  13.  
  14. /*
  15.  * Start Editing here
  16.  */
  17.  
  18.  
  19. //get Backgrounds in PNG Format
  20. //And Fonts in TIFF format
  21. $handle = opendir("captcha");
  22. while ($file = readdir($handle)){
  23.   if (preg_match("@.*?\.png$@i", $file))
  24.     $BgArray[] = "captcha/".$file;
  25.   elseif (preg_match("@.*?\.ttf$@i", $file))
  26.     $FontArray[] = "captcha/".$file;
  27. }
  28. closedir($handle);
  29.  
  30. //possible Chars
  31. $CharStr = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
  32. $FontSize = 26;
  33.  
  34. //Picture Attributes
  35. $Width = 200;
  36. $Height = 60;
  37.  
  38. //PAdding - distance from borders
  39. $Padding = 10;
  40.  
  41. //Just some random chars, to create the salt for hashing.
  42. $Salt = "23lfb9$5%§0pr(),f.";
  43.  
  44.  
  45. /*
  46.  * Stop Editing here, except you know what you do
  47.  */
  48.  
  49.  
  50.  
  51. //Start of creation
  52. //5 chars per captcha
  53. For ($i=0;$i<5;$i++){
  54.   //Create captcha
  55.   $cap .= $CharStr[mt_rand(0,strlen($CharStr)-1)];
  56. }
  57.  
  58. //Create Image
  59. $Image = imagecreatetruecolor($Width,$Height);
  60.  
  61. imagefill($Image,0,0, 0xFFFFFF);
  62.  
  63. //Create a Image From possbile background
  64. $ImageBgPath = $BgArray[mt_rand(0,count($BgArray)-1)];
  65. $ImageBg = imagecreatefrompng($ImageBgPath);
  66.  
  67. //get the size of current bg image
  68. $Size = getimagesize($ImageBgPath);
  69.  
  70. //Now calc the max. x and max y-offset.
  71. $MaxXOffset = $Size[0] - $Width;
  72. $MaxYOffset = $Size[1] - $Height;
  73.  
  74. //Now create the Chars
  75. for ($i=0; $i<5;$i++){
  76.   //Current Char
  77.   $CurChar = $cap[$i];
  78.  
  79.   //Get Random Font
  80.   $CurFont = $FontArray[mt_rand(0,count($FontArray)-1)];
  81.   $CurFontSize = $FontSize;
  82.  
  83.   $neg = array(-1,1);
  84.   $CurAngleDirection = $neg[mt_rand(0,1)];
  85.   $CurAngle = mt_rand(0,20) * $CurAngleDirection;
  86.  
  87.   //CurX
  88.   $WidthPerChar = ($Width - 2 * $Padding ) / 5;
  89.   $CurX = $Padding + $i * $WidthPerChar;
  90.   $CurY = mt_rand($CurFontSize+$Padding, $Height - $Padding);
  91.  
  92.   //write text
  93.   imagettftext($Image, $CurFontSize, $CurAngle, $CurX, $CurY, 0x626262, $CurFont, $CurChar);
  94. }
  95.  
  96. //insert the Background
  97. imagecopymerge($Image, $ImageBg,0,0,mt_rand(0,$MaxXOffset), mt_rand(0,$MaxYOffset),$Size[0],$Size[1],mt_rand(60,70));
  98.  
  99. //To compare the Hash with passed Data, save hash to session
  100. $_SESSION["Captcha"] = md5($Salt.$cap.$Salt);
  101.  
  102. header('Content-type: image/png');
  103. imagepng($Image);
  104. imagedestroy($Image);
  105. ?>
  106.  


To compare, if the ৺captcha was entered correct, use sth like that:

  1. if ($_SESSION["Captcha"] == md5($Salt.$_POST["Captcha"].$Salt){
  2.   echo "captcha correct";
  3. }else{
  4.   echo "captcha wrong";
  5. }


Hint:
Some "Brute-Force"-Bots are looking if the submit was successful - so if it wasn't, include a pic named "success_reply.png" and write "in the Picture" that the capture code was wrong.
(Humans will be able to read the text in the Picture, but the bot will "find" the words "success" in sourcecode)

Update:
I added the nocache headers, and changed the "rand" to "mt_rand" - Why?
Have a look at my post ৺rand or mt_rand.

Related Tags:

Stay tuned:

r a t y y

Top 25 Tag-Cloud (last 14 days):

Trackbacks on this post:

Comments on this post:

Earl
2009-07-24 23:44:11
Thx a lot, you've made my day!

Leave a Comment:

Captcha-Code:        reload
Name:
Captcha:
Comment:

Donate!

Like my stuff? Feel free to donate!
 
Modellbau Forum pspad Browser-Statistiken WhatPulse logo dog-net.org Valid XHTML 1.0 Transitional CSS ist valide!

DevelopmentPHP | 2009-10-14 02:08:39

LeadImage

ImageCopyMergeAlpha

The GD-Lib is a very powerfull extension for PHP.

but in one case, it really fails.

read more...

DevelopmentPHP | 2009-08-26 16:35:21

LeadImage

rand or mt_rand?

Random numbers are often useful - but those are these pseudo random numbers really random?

read more...

DevelopmentPHP | 2009-08-19 23:27:25

LeadImage

Easy Permission Management System

Heres a sample of a easy ৺permission management system.

read more...

DevelopmentPHP | 2009-07-09 03:22:13

LeadImage

MySQL Connection Class

A Long time ago, i wrote a Class, that makes ৺SQL-Querys easier. Nearly everything is done without caring about all the PHP ৺SQL-Functions.

read more...

DevelopmentPHP | 2009-07-09 03:22:05

LeadImage

MakeNiceSize

This is the php function, i use to create user friendly file size strings. Sizes like 215742435 byte or 0,00000000023 GB are NOT user friendly.

read more...

DevelopmentPHP | 2009-07-09 03:21:44

LeadImage

Dynamic Style Sheets

Copyright © 2008 - 2010 | by dog.net Development | Imprint | Load in 1.15223