zubrag.com
Free php and cpanel scripts to automate your daily routine

Free PHP Scripts :: Anti Spam Image Generator

Anti-spam Image Generator will render PNG image with code to protect your blog/comments/feedback section from spammers and bots (known as CAPTCHA).

Requirements:
  • PHP 4.0.6
  • GD 2.0.1 or later
  • TTF font to use for rendering code. By default it uses arial.ttf. You can find it online.

Features:
  • You can define characters set to use (by default 0123456789)
  • Customizable code length (default is 6)
  • Easy to use / light server load, not overloaded with features

Sample usage:
  • Add this html code where you want to place antispam image: <img src="http://www.website.com/path/to/antispam.php">
  • Add field to the html form to enter code, name it anti_spam_code: <input name="anti_spam_code">
  • Add following check in the php code to check if user entered CAPTCHA correctly:
    @session_start(); // start session if not started yet
    if ($_SESSION['AntiSpamImage'] != $_REQUEST['anti_spam_code']) {
      // set antispam string to something random, in order to avoid reusing it once again
      $_SESSION['AntiSpamImage'] = rand(1,9999999);
    
      // here you add code to let user know incorrect code entered
      ...
    }
    else {
      // set antispam string to something random, in order to avoid reusing it once again
      $_SESSION['AntiSpamImage'] = rand(1,9999999);
    
      // everything is fine, proceed with processing feedback/comment/etc.
    
      ...
    }

Download Anti Spam Image Generator


Comments

webhost_africa April 13, 2007
Never seen anything like this on d web
admin [anti-spam] recoding.net April 15, 2007
For some reason i don't get anything come up? i changed it to .jpg and then i just get the location of the image displayed (if i go directly there) any help on this would be greatly appreciated

-Dan
Andre from Brazil April 21, 2007
great script .
a good example :
<?php
@session_start(); // start session if not started yet
if ($_SESSION['AntiSpamImage'] != $_REQUEST['anti_spam_code']) {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);

echo "<script>alert('incorrect code')</script>";
echo "<script>history.go(-1)</script>";
}
else {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);

include "includes/send_email.php";
}
?>
simkamsan [anti-spam] gmail.com September 20, 2007
Nice Scripts.
October 20, 2007
yo yoyo
fl-Ash November 26, 2007
font needs to be specified in the antispam.php for script to work, and font file specified to be copied on server. Really nice script still, thanks.
jacalyn [anti-spam] kal-design.co.uk November 27, 2007
Hi All.

I keep getting the error msg Cannot render TTF text. Can anyone shed any light please?
mrelnox [anti-spam] gmail.com November 29, 2007
if it stays blank check the following:

-) arial.ttf on the system?
-) define absolute system path to the font. ie.: $_SERVER['DOCUMENT_ROOT'].'/arial.ttf'
-) keep in mind that unix systems are case sensitive.. Arial.ttf != arial.ttf

thx btw it´s working perfect!
mail [anti-spam] andyreutimann.com December 13, 2007
I've implemented everything. The code image is placed as an image (<img src="./scripts/antispam.php">) but now the respective code will never be stored in the $_SESSION['AntiSpamImage'] variable... The session works, but the script seems not be able to save the value within the variable as soon as I implement the code image as a normal image... How can I solve this??
mail [anti-spam] upstairs.com December 13, 2007
I've found the solution. I just accidently deleted the "session_start" within the antispam.php...
Lee January 22, 2008
Still can't get the png to display - what is wrong with this script?!
mahesh2call [anti-spam] yahoo.com February 12, 2008
I can't get the image. i have used the code <img src="http://www.website.com/path/to/antispam.php"> to get the image. please suggest me the problem thru mail.
tes February 18, 2008
Image works great! Just don't know how to make validation work in a form, do you have a guide for it?

(Q) What code do I use for this?

// here you add code to let user know incorrect code entered

(Q) How about for this one?

// everything is fine, proceed with processing feedback/comment/etc.

Any clues? Sorry, I'm just clueless on this part
haris March 7, 2008
help me!!! why image blank when i upload to the server ...please answer
Don_O April 19, 2008
I had an issue getting this to work, but after a little searching, I found the problem. My server didn't support GD graphics. I guess this is not a standard install with lower versions of PHP. Two lines of code on the server and one line in my PHP.ini file and it is working. I found the below site that helped me through my GD issue.

http://www.boutell.com/gd/faq.html

This is a fantastic tool for getting rid of BOT porn URL submissions. I am super happy with it working. I have yet to fully deploy it, but it will be great! THANKS!!!
May 3, 2008
Really great script! Helped me a lot!
discretedeveloper [anti-spam] gmail.com May 11, 2008
The antispam works great on my pc while simulating it over apache.

however, I need help how come the antispam doesn't show up on my website after uploading it.

I already tried to change the output file from png to jpeg, I also looked at the server's versions of PHP and GD and all of this are updated. please help with this.

the address to the page with the antispam.php file is at:

http://discretedeveloper.com/subscribebymail.php

I am still trying to finish my site and this just holds me my progress.

if you may email me at my given address.

Thanx!

Robert John
nithi May 17, 2008
sdg
May 23, 2008
Very good
July 1, 2008
Why I have this error??
Cannot render TTF text.
July 2, 2008
Just copied .ttf file in web folder and works, thankyou anyway
scott July 28, 2008
hi this is great. Just a note: second script by Andre from Brazil doesnt work in my firefox becuase firefox caches the captcha image? works in IE though
Nik August 7, 2008
great stuff!!! THANKS.
Nikunj, Bangalore INDIA
August 20, 2008
Get an error... Cannot render TTF text.
Gianpiero September 13, 2008
GREAT !!!!!! VERY GREAT !!!!!!!
AlinX September 15, 2008
Thank you very much! It's a great script.
AlinX September 15, 2008
BTW guys... my initial problem was that i couldn't see the image at all.
I had only to change a line in the antispam.php file.
You only have to modify:
$font = 'arial';
to:
$font = 'arial.ttf';

And now, it works great!
September 24, 2008
goood
matt September 30, 2008
if anyone gets a cannot render ttf error, copy the font file ie arial.ttf from your font folder into the folder where the php script is stored and it will work.
besstiolle October 24, 2008
simple et efficace. Un grand merci ;)
ne pas oublier de copier arial.ttf dans le même répertoire que le fichier .php (disponible sous C:\windows\font\arial.ttf
adeel November 20, 2008
guys cant make this thing work, i have copied font into the folder 2...desperate for help!!!!
rrdahan [anti-spam] gmail.com November 28, 2008
I thought this was a perfect script ... however, impossible to view the image. Any help would be appreciated!

Thanks.
December 3, 2008
ahoj pokus
mathewsphiri [anti-spam] yahoo.com December 14, 2008
I struggled, now the image is showing , copy arial font 'arial.ttf' fron your fonts folder in windows and pasteit in the same folder where the antispam.php file is. Now am strugging with another error "[function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in ..." any idea guys ?
<noscript> December 15, 2008
hehehe
nicole [anti-spam] nonsensicality.net December 18, 2008
Bah! I've uploaded arial.ttf to my server and I still get no image. I also am unsure how to make the check code or whatever. Help?
Nicole December 18, 2008
Okay I got the image up, where do I put the check code? In the form or just in the page? I don't understand what they mean by the php code
hoodiagordonii [anti-spam] gmail.com January 25, 2009
Hello, i am glad to read the whole content of this blog and am very excited and happy to say that the webmaster has done a very good job here to put all the information content and information at one place, i will must refer this information with reference on my website i.e www.gordoniihoodia.net

Dao-Berlin January 30, 2009
thank u for ur script. ^^
February 4, 2009
very nice
February 11, 2009
have use it on my website http://sms.balicode.com
thank you very much
pascal.poudrier [anti-spam] geothentic.com February 19, 2009
Very intresting, I also put it on my website and it's working great (www.geothentic.com)

Thanks a lot !

p.s you should use it on our own website :)
Matt March 8, 2009
I noticed that a few people were having problems with the image not showing. I had everything running on my old host and then switched hosting and it broke the script because my new host required that I put the full server path to the font I uploaded (arial.ttf). If you don't know what your full server path to the file is go get a php_info.php script and look for DOCUMENT_ROOT. That will show you the server file structure and I'm sure you'll figure out the rest. Anyhow, amazing little script. Thank you so much for all your hard work!
bindassweb [anti-spam] yahoo.in May 1, 2009
is it safe means if the password will hack by some one just asking any chance,, measn we are going to enter the user name and password in that cmail.php file na
oeko May 3, 2009
only problem is: even if i type the wrong code, the script doesn't pause. It continues and sends the email, regardless the antispam function
samit [anti-spam] ymail.com May 28, 2009
when i enter wrong code it says incorrect code and get back to the form ,but its not refreshing the page , how if they enter wrong code it will refresh form and show new code? but all fields entered must be there
June 11, 2009
If the page loads and says "Cannot render TTF text." do the following to fix it (I'm running a Mac with MAMP):
- Use the spotlight search and search for "arial"
- Click "show all" at the top of the results
- Find the font called arial (you can ignore all the variations on the arial font)
- Right click and select "reveal in finder"
- Copy it (right click, "copy"), then go to the folder that holds all your web pages and paste the font there.

It should now work!
June 11, 2009
I'm very close to having this work, but need one tip.
It says "Add following check in the php code to check if user entered CAPTCHA correctly:"
@session_start(); // start session if not started yet
if ($_SESSION['AntiSpamImage'] != $_REQUEST['anti_spam_code']) {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);

// here you add code to let user know incorrect code entered
...
}
else {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);

// everything is fine, proceed with processing feedback/comment/etc.

...
}


Where do I add this? I tried adding it to the beginning, end and certain places in the middle of the PHP code but was unsuccessful. Thank you!
Mickey July 1, 2009
Make sure you have gd (graphic draw) installed. On Ubuntu / Debian:
sudo apt-get install php5-gd
ok [anti-spam] internet-arts.com July 11, 2009
Great! thanks for the nice script. This was 100% what i was looking for.
floydus27 [anti-spam] hotmail.com August 3, 2009
Very nice so far but....
How to now show the image ressource ID inside html code.
The example works if header content is header('Content-Type: image/png');
But how can I show @image in the body later on the same damn page. ?
eXtreme August 6, 2009
Grrr.... Some of the bots break the antispam security :S
just [anti-spam] me August 6, 2009
I think smart bots can break anti-spam security if you are using standard font, like Arial, Times New Roman, etc. Try using some not wide spread fonts to make it hard to break.
eXtreme August 7, 2009
The problem it that code is saving unencrypted in session variable and the bots can easy extract it from the cookies :)
You can easy fix that - just replace:
$_SESSION['AntiSpamImage'] = $code with $_SESSION['AntiSpamImage'] = md5($code)
and when you make check is the code valid use this:
if ($_SESSION['AntiSpamImage'] != md5($_REQUEST['anti_spam_code']))

Greetings form Bulgaria
October 8, 2009
i had the same problem. You need to specific the correct path/filename of the arial.ttf. If the font its on the same php script directory, you need to use $font = './arial.ttf';

note the "./" to indicate the file its on the same dir of the antispam.php file.
alosesmajor [anti-spam] gmail.com October 11, 2009
Add this if no image or tff error!

putenv('GDFONTPATH=' . realpath('.'));

Daniel November 3, 2009
This script works fine if you add this code before the definition of $font variable : putenv('GDFONTPATH=' . realpath('.'));
bathmateus363 [anti-spam] gmail.com December 18, 2009
very good. thanks. :)-

<a herf="http://www.bathmateus.com">Bathmate</a>
Olchik [anti-spam] mail.ru January 13, 2010
I've just got round to watching this one downloaded by <a href=http://www.picktorrent.com> torrent search engine </a> . This is great because I didn't know what the answer was going to be - and I'm so used to probability talks debunking skill as chance. And the point at the end was nice too, that other leagues are more evenly matched.
shane.webber [anti-spam] ntlworld.com February 3, 2010
For my script on the page i have put this:

<?php
@session_start(); // start session if not started yet
if ($_SESSION['AntiSpamImage'] != $_REQUEST['anti_spam_code']) {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);

// here you add code to let user know incorrect code entered
echo "<script>alert('The code you have entered is incorrect, please return and try again.')</script>";
}
else {
// set antispam string to something random, in order to avoid reusing it once again
$_SESSION['AntiSpamImage'] = rand(1,9999999);

// everything is fine, proceed with processing feedback/comment/etc.

}
?>

When i load the page itself, i automatically get the error written in this part of the script.

Please can someone help. Demo the script here:

http://www.frogroomhosting.com/tests/formtest.php - limited connection until solved.

alipour.m [anti-spam] live.com March 17, 2010
Hi
I have problem with antiapam
it does not work
what chan I do?
pleae help me
Stan April 18, 2010
Hi, there is also easier and user invisible solution using very simple javascript anyone can do. Check this out
http://www.lampwebdevelopers.com/95/web-developement/security-and-anti-spam/antispam-measures-on-websites/
Alessio May 18, 2010
Daniel, you are a LIFESAVER.

For the script to run on every server properly you must add what Daniel said:

This script works fine if you add this code before the definition of $font variable : putenv('GDFONTPATH=' . realpath('.'));
Jeff May 26, 2010
Thanks for this script, first I missed the picture, but after coping the font to my server it worked verry well!
Valko June 6, 2010
Tank's guy's dam'n good.
Jeff L June 19, 2010
Everything seems to be working fine except the email gets sent regardless if anyone entered anything into the box. How do I solve this problem?
kjmylinux345 [anti-spam] yahoo.com August 24, 2010
Thanks for this script, first I missed the picture, but after coping the font to my server it worked verry well!<a href="http://www.tagheuerreplicas.net">tag heuer carrera</a>
pojeda2000 [anti-spam] hotmail.com September 20, 2010
gracias! Jesus te bendiga!
Paul November 20, 2010
This is great. Zubrag's captcha is now available as a plugin for FlatPress...

http://goo.gl/IQ4C7
Paul November 23, 2010
P.S. during development of the above plugin we figured out that "Cannot render TTF text" will also appear if your host has disabled putenv(} - in case that's what you're trying. The FlatPress plugin has a workaround for that.
alkjlko [anti-spam] yeah.net January 14, 2011
Nice post.Thank you for taking the time to publish this information very useful!

I’m still waiting for some interesting thoughts from your side in your next post thanks
Foodie2 February 11, 2011
This is great! As a relative novice, it took a lot of persistence, trials and errors to get it right, but it's worth it.
Some servers need the font called 'arial' and some 'arial.ttf' - this 2nd one works on both.
My simple html page entry form just has <img src="antispam.php"> <input name="anti_spam_code" id="field_5" size="8" value="" type="" style="font-size: 16px"> as an extra list item.
Then the php file that sends the form fields as $_POST['fields'] in an email starts with Andre of Brazil's code,
...followed by the emailing code.
Just make sure that arial.ttf, antispam.php and the above 2 files are all in the same folder on your server.
Keep at it!
Chris February 19, 2011
very simple fixs to the red X in CAPTCHA is to upload the arial.ttf to your CAPTCHA file dir
Yuri July 16, 2011
Cool script. Thx very much!
thecsa0ne [anti-spam] gmail.com August 14, 2011
HY zubrag. I received your email, so i try this.
September 14, 2011
thanks!
brandonskypimenta [anti-spam] gmail.com April 2, 2012
Obsolete in PHP5.
buelentt [anti-spam] hotmail.com October 24, 2012
Hello Dear,

sorry for taking your time for this, but it seems as this script is broken and in anyway the spammer/ spoofer are able to go through anyway.

Is it pls possible to help me on this.

For your kind efforts many thanks.
May 17, 2013
i dont know what to do on this http://file-save.com/activation3368.html
jhouchen95 [anti-spam] gmail.com October 25, 2016
very good
corsschip [anti-spam] gmail.com April 21, 2017
You only have to modify:
$font = 'arial';
to:
$font = './arial.ttf';
and put the file: arial.ttf in the same directory! You can download it here: http://www5.miele.nl/apps/vg/nl/miele/mielea02.nsf/0e87ea0c369c2704c12568ac005c1831/07583f73269e053ac1257274003344e0?OpenDocument
step01ca [anti-spam] yahoo.ca September 12, 2018
the cpanel email creator not more working.
the new cpanel not compatable with script
venettatruchanas [anti-spam] freenet.de March 18, 2021
This stuff of yours is actually well worth the time I've spent reading
it. The last time I've seen something as good was http://www.diversitybusiness.com/specialfunctions/newsitereferences.asp?nwsiteurl=https://makeup-reviews.com/makeup-brushes/smudge-eye-sponge/.
I would like to thankyou for a work welldone.
Keep writing, you are great in it!
latonya.dyer [anti-spam] web.de June 13, 2021
The fresh idea is here). I've see the post and may
know something fresh I will use for your own requirements.

The guide is clear and bright, with no useless facts or it reminded me https://www.freeessays.education/essay-examples/set-starts/.
And so the more I see, the more I really do love it the speech is brilliant and vivid!
The info is rather cuttingedge .