Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[TUT] Captcha Image Tutorial (No Spam Registrations and emails!)

Junior Spellweaver
Joined
Jul 6, 2008
Messages
173
Reaction score
2
Well its easier than you think

Things Using
  • 1 Font File
  • 2 Images
  • 2 Php Files

Example


So lets get the php files together.
index.php
PHP:
<?php
//Creates the session to make sure the image matches text, and creates the form
session_start();

if(isset($_POST['submit']) && !empty($_POST['code'])){
$ses = $_SESSION['captcha'];
if($ses == $_POST['code']){
echo "Code is correct!";
}else{
echo "Code is incorrect!";
}
}else{
echo "<img src='captcha.php'><br>";
echo "<form action='' method='post'>"
	."<input type='text' name='code'>"
	."<br><input type=image src=others/submit.bmp name='submit' value=Submit alt=Submit><a href=index.php><img src='Others/refresh.bmp' border=0></a><br>"
	."</form>";
}
?>

captcha.php
PHP:
<?php
//Creates The Image
session_start();
$im = imagecreatefromjpeg ("others/image.jpg");
$rand1 = rand(1,255);
$rand2 = rand(1,255);
$rand3 = rand(1,255);
$color = imagecolorallocate($im, $rand1, $rand2, $rand3);
$text = rand(1000, 9999);
$font = 'others/TACOBOX_.TTF';
$size = 20;
imagettftext($im, $size, 0, 5, 28, $color, $font, $text);
header('Content-type: image/jpg');
imagejpeg($im);
imagedestroy($im);
$_SESSION['captcha'] = $text;
?>

Download the attachment for everything together
 

Attachments

You must be registered for see attachments list
Junior Spellweaver
Joined
Jul 6, 2008
Messages
173
Reaction score
2
Sorry in index.php, if you download it

Replace it with the one in this post
- Thanks
 
Experienced Elementalist
Joined
Dec 27, 2006
Messages
288
Reaction score
4
Why write a tutorial for something that you can find in less than 10 seconds on google? Especially when the tutorial you're writing isn't even as good the ones you can find on google.
 
Junior Spellweaver
Joined
Jul 6, 2008
Messages
173
Reaction score
2
You may find that 10 sec on google BUT

But i customized this one.
And people can write a source off this one.

Its just a cool little captcha this for forms
so F*** Off
 
something
Joined
Dec 26, 2007
Messages
423
Reaction score
12
Re king Izu, can you please cool down? lol...
 
Joined
Dec 1, 2007
Messages
2,795
Reaction score
480
I had captcha images honestly, I swear to God I write them correctly and it turns out invalid, and I'm like wtf, but any ways nice tutorial I recently made one for an example in SAMS teach yourself e-book.
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
Nice tutorial, quite helpful for beginners :).
I always used MySQL to store the IP and code...but this is just as good (or maybe better).

Anyways, the first line is redundant:
PHP:
$ses = $_SESSION['captcha'];
if($ses == $_POST['code']){
Also would I strongly recommend indention, like this:
PHP:
<?php
session_start(); //Creates the session to make sure the image matches text, and creates the form

if (isset($_POST['submit']) && $_POST['code'])
{
    if ($_SESSION['captcha'] == $_POST['code'])
    {
        echo 'Code is correct!';
    }
    else
    {
        echo 'Code is incorrect!';
    }
}
else
{
    echo '<img src="captcha.php" alt="Captcha"><br>';
    echo '<form action="index.php" method="post">
          <a href="index.php"><img src="Others/refresh.bmp"></a><br>
          <input type="text" name="code"><br>
          <input type="submit" name="submit" value="Submit">
          </form>';
}
?>
Also adding different angles to each letter, and size and colour would be even better :), because these images can be cracked quite easily these days. And using PNG instead of BMP can decrease bandwidth usage quite a bit :)
 
Junior Spellweaver
Joined
Jul 6, 2008
Messages
173
Reaction score
2
Ok thanks, ill look into angels if i can.

Well, do you think a more dotted font or a font with lines through would make it just as good?

I new a had to get some cc ;)
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
Best is to use a different font for each letter ;)
 
Back
Top