...

View Full Version : Image Validation for registering a new user



lakshmi1234
02-06-2007, 12:11 PM
Hi,

Iam new to PHP,Icreated one register page with some fields,.........


Now I want make image verification for security..

Please help me how to code for image validaton......

meth
02-06-2007, 01:40 PM
google > php captcha

lakshmi1234
02-07-2007, 06:43 AM
hi,i have gone through the link send by you,tell me where can i get relevant information for image validation in the link.............

neomaximus2k
02-07-2007, 01:43 PM
Well here is my captcha script that i use, i have attached all the files needed in a zip format, of course mine looks this way because of this damn smartbot that is causing so many forums grief but you can change it to your hearts content.



<?php
session_start();

$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

// generate the verication code
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand = substr(md5($rand), 0, 5);
// choose one of four background images
$bgNum = rand(1, 3);
$font = $_SERVER['DOCUMENT_ROOT'] . "/ConvectionRegular.ttf";

// create an image object using the chosen background
$image = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'] . "/images/verification_background".$bgNum.".jpg");

$textColor = imagecolorallocate ($image, 82, 82, 82);

// write the code on the background image
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand1 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand2 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand3 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand4 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand5 = strtoupper(substr(md5($rand), 0, 1));

$thecode = $rand1.$rand2.$rand3.$rand4.$rand5;

//echo $font;
imagettftext($image, 18, rand(-12, 12), 7, 26, $textColor, $font, $rand1);
imagettftext($image, 18, rand(-12, 12), 29, 31, $textColor, $font, $rand2);
imagettftext($image, 18, rand(-12, 12), 41, 21, $textColor, $font, $rand3);
imagettftext($image, 18, rand(-12, 12), 66, 24, $textColor, $font, $rand4);
imagettftext($image, 18, rand(-12, 12), 86, 33, $textColor, $font, $rand5);


// create the hash for the verification code and put it in the session
$_SESSION['paramil_verification'] = $thecode;

// send several headers to make sure the image is not cached
header("Expires: Mon, 26 Jul 1992 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

// send the content type header so the image is displayed properly
header('Content-type: image/jpeg');

// send the image to the browser
imagejpeg($image);

// destroy the image to free up the memory
imagedestroy($image);
?>


that will help you along

westmatrix99
02-25-2007, 01:29 PM
I get this error:

Fatal error: Call to undefined function imagecreatefromjpeg() in c:\Inetpub\wwwroot\usermail\captcha.php on line 14

neomaximus2k
02-25-2007, 02:44 PM
Looks like GD isn't installed on the system

westmatrix99
02-25-2007, 02:46 PM
Ok so how to install?

redfroc
03-01-2007, 06:56 AM
To install GD, open your php.ini, find line ;extension=php_gd.dll or ;extension=php_gd2.dll. remove the ";". done!

neomaximus2k, could you please show the test script? I've try to make one but I cannot compare the results.

Thank you...

westmatrix99
03-01-2007, 07:12 AM
Hi redfroc
I have got it to work but would like to now just refresh the image without refreshing the whole page.

seonet
03-01-2007, 05:46 PM
Thank you.
I try modify it to more simple.
:D


<?php
session_start();
$sAlp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$iInd = 5;
for($i = 0; $i < $iInd; $i ++)
{
$iRnd = rand(0, strlen($sAlp) - 1);
$aStr[$i] = substr($sAlp, $iRnd, 1);
}
$sStr= join("", $aStr);
$im = imagecreate(50, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 200, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 18, 3, 2, $sStr, $text_color);
$_SESSION['regcode'] = $sStr;

header("Expires: Mon, 26 Jul 1992 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-type: image/gif');

imagegif($im);
imagedestroy($im);
?>

westmatrix99
03-01-2007, 06:00 PM
This is one is cool:
But how do I just refresh the image without the whole page?


<form name="form1" method="post" action="">
<table width="500" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="16%" align="right" nowrap><div align="left"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">User Name:</font></div></td>
<td colspan="2"><div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="username" type="text" id="username" onFocus="MM_displayStatusMsg('Please enter your User Name');return document.MM_returnValue" maxlength="50">
</font></div></td>
</tr>
<tr>
<td width="16%" align="right" nowrap><div align="left"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Password:</font></div></td>
<td colspan="2"><div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="password" type="password" id="password" onFocus="MM_displayStatusMsg('Please enter your Password');return document.MM_returnValue" maxlength="50">
</font></div></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Code:</font></td>
<td width="19%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><img src="img.php" alt=""> </font></td>
<td width="65%"><a href="#"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">refresh</font></a></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
</tr>
<tr>
<td width="16%"><div align="left"><font face="Verdana, Arial, Helvetica, sans-serif"><font size="2"></font></font></div></td>
<td colspan="2"><div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Log In">
</font></div></td>
</tr>
</table>
</form>

redfroc
03-02-2007, 06:03 AM
hi westmatrix99
where is the action when form is submitted? and how to compare between image code and user input?

mm.. I think we should use script like AJAX to make new image code without refreshing page (I think, I cannot make sure). Or put image creation lines in a function, so we can just load the function.

westmatrix99
03-02-2007, 06:30 AM
The form will be submitted to anything like mail or database but do not know how to make the captcha and form work.

Cheers
West

redfroc
03-02-2007, 03:15 PM
Yes, westmatrix, I can't either. :(
May somebody could help us...?

Thank you very much... :)

Inigoesdr
03-02-2007, 07:21 PM
You can refresh it by setting the ID of the image tag and changing the URL like this:

<img src="captcha.php" id="image" /> <a href="#" onclick="javascript: document.getElementById('image').src = 'captcha.php?' + Math.random();">Refresh Image</a>
Just make sure you aren't using the QUERY_STRING for anything in the file.

westmatrix99
03-02-2007, 07:41 PM
Cool thanks, it works great.
Thank you...


<form name="form1" method="post" action="">
<table width="60%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="40%" align="right"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">User Name:</font></td>
<td width="60%"><input name="username" type="text" id="username" onFocus="MM_displayStatusMsg('Please enter your User Name');return document.MM_returnValue" maxlength="50"></td>
</tr>
<tr>
<td width="40%" align="right"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Password:</font></td>
<td width="60%"><input name="password" type="password" id="password" onFocus="MM_displayStatusMsg('Please enter your Password');return document.MM_returnValue" maxlength="50"></td>
</tr>
<tr>
<td width="40%"><img src="untitled.php" id="image" /> <a href="#" onclick="javascript: document.getElementById('image').src = 'untitled.php?' + Math.random();">Refresh Image</a></td>
<td width="60%"><input type="submit" name="Submit" value="Log In"></td>
</tr>
</table></td>
</tr>
</table>
</form>

Cheers

redfroc
03-03-2007, 11:26 AM
finally I found the way...
please check it out! :thumbsup:



<?php

if ($_GET['image']==1)
{
session_start();

$thecode;
session_register('thecode');

$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

$rand = substr(str_shuffle($alphanum), 0, 5);
$rand = substr(md5($rand), 0, 5);

$bgNum = rand(1, 3);

$font = "c:/windows/fonts/arial.ttf";

$image = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT']."/ikc/bg".$bgNum.".jpg");
$textColor = imagecolorallocate ($image, 82, 82, 82);

$rand = substr(str_shuffle($alphanum), 0, 5);
$rand1 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand2 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand3 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand4 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand5 = strtoupper(substr(md5($rand), 0, 1));

$thecode = $rand1.$rand2.$rand3.$rand4.$rand5;

imagettftext($image, 18, rand(-12, 12), 7, 26, $textColor, $font, $rand1);
imagettftext($image, 18, rand(-12, 12), 29, 31, $textColor, $font, $rand2);
imagettftext($image, 18, rand(-12, 12), 41, 21, $textColor, $font, $rand3);
imagettftext($image, 18, rand(-12, 12), 66, 24, $textColor, $font, $rand4);
imagettftext($image, 18, rand(-12, 12), 86, 33, $textColor, $font, $rand5);

$_SESSION['paramil_verification'] = $thecode;

header('Content-type: image/jpeg');

imagejpeg($image);

$_SESSION['ns'] = $thecode;

imagedestroy($image);
}

elseif (!isset($_POST['u']))
{
echo "<html>";
echo "<head>";
echo "<title>GD Test</title>";
echo "</head>";
echo "<body>";
echo "<img src=\"gdcode.php?image=1\">";
echo "<form method=\"post\" action=\"gdcode.php\">";
echo "<input type=\"text\" name=\"random\" value=\"\">";
echo "<input type=\"submit\" value=\"Test\">";
echo "<input type=\"hidden\" name=\"u\">";
echo "</form>";
echo "</body>";
echo "</html>";
}

elseif (isset($_POST['random']))
{
session_start();

$random = $_POST['random'];
$random = trim($random);

if ($_SESSION['ns'] == $random)
{
echo "You are verified!";
$_SESSION['vf'] = "yup";
}

else
{
echo "Wrong code! Please go back and get verified.";
$_SESSION['vf'] = "hn";
}

}

?>

westmatrix99
03-03-2007, 12:54 PM
Can't see image?

redfroc
03-03-2007, 02:45 PM
Can't see image?

find 'gdcode.php' and change to yours.



echo "<img src=\"gdcode.php?image=1\">";
echo "<form method=\"post\" action=\"gdcode.php\">";

I hope it works just like mine...
please let me know if yours get works.
cheers :D:thumbsup:

westmatrix99
03-03-2007, 02:54 PM
Cool did that, but a bit lost.

This is your script:

<?php
if ($_GET['image']==1)
{
session_start();
$thecode;
session_register('thecode');
$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand = substr(md5($rand), 0, 5);
$bgNum = rand(1, 3);
$font = "c:/windows/fonts/arial.ttf";
$image = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT']."/ikc/bg".$bgNum.".jpg");
$textColor = imagecolorallocate ($image, 82, 82, 82);
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand1 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand2 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand3 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand4 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand5 = strtoupper(substr(md5($rand), 0, 1));

$thecode = $rand1.$rand2.$rand3.$rand4.$rand5;

imagettftext($image, 18, rand(-12, 12), 7, 26, $textColor, $font, $rand1);
imagettftext($image, 18, rand(-12, 12), 29, 31, $textColor, $font, $rand2);
imagettftext($image, 18, rand(-12, 12), 41, 21, $textColor, $font, $rand3);
imagettftext($image, 18, rand(-12, 12), 66, 24, $textColor, $font, $rand4);
imagettftext($image, 18, rand(-12, 12), 86, 33, $textColor, $font, $rand5);

$_SESSION['paramil_verification'] = $thecode;

header('Content-type: image/jpeg');

imagejpeg($image);

$_SESSION['ns'] = $thecode;

imagedestroy($image);
}

elseif (!isset($_POST['u']))
{
echo "<html>";
echo "<head>";
echo "<title>GD Test</title>";
echo "</head>";
echo "<body>";
echo "<img src=\"imgcode.php?image=1\">";
echo "<form method=\"post\" action=\"gdcode.php\">";
echo "<input type=\"text\" name=\"random\" value=\"\">";
echo "<input type=\"submit\" value=\"Test\">";
echo "<input type=\"hidden\" name=\"u\">";
echo "</form>";
echo "</body>";
echo "</html>";
}
elseif (isset($_POST['random']))
{
session_start();
$random = $_POST['random'];
$random = trim($random);
if ($_SESSION['ns'] == $random)
{
echo "You are verified!";
$_SESSION['vf'] = "yup";
}
else
{
echo "Wrong code! Please go back and get verified.";
$_SESSION['vf'] = "hn";
}
}
?>


This is my script for image:

<?php
//Start the session so we can store what the code actually is.
session_start();
//Now lets use md5 to generate a totally random string
$md5 = md5(microtime() * mktime());
/*
We dont need a 32 character long string so we trim it down to 5
*/
$string = substr($md5,0,5);
/*
Now for the GD stuff, for ease of use lets create
the image from a background image.
*/
$captcha = imagecreatefrompng("./captcha.png");
/*
Lets set the colours, the colour $line is used to generate lines.
Using a blue misty colours. The colour codes are in RGB
*/
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);
/*
Now to make it a little bit harder for any bots to break,
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
/*
Now for the all important writing of the randomly generated string to the image.
*/
imagestring($captcha, 5, 20, 10, $string, $black);
/*
Encrypt and store the key inside of a session
*/
$_SESSION['key'] = md5($string);
/*
Output the image
*/
header("Content-type: image/png");
imagepng($captcha);
?>

Not sure how this works, you seem to be a much better coder than me.
Cheers

westmatrix99
03-03-2007, 04:50 PM
If I use your code, the image is blank.
Which your code should on mine, work if it's working on your machine?
If I change it to my image page using the above the code does not get verified, cause it's a different code to yours.


Wrong code! Please go back and get verified.

Not sure how to implement your version.
Cheers

westmatrix99
03-03-2007, 05:19 PM
Ok got it work but get an error on the page:



Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at c:\Inetpub\wwwroot\MAINCAPTCHA\imgcode.php:39) in c:\Inetpub\wwwroot\MAINCAPTCHA\imgcode.php on line 55
Error: You must enter the code correctly


Any ideas of getting around this?



<?php
if ($_GET['image']==1)
{
//Start the session so we can store what the code actually is.
session_start();
//Now lets use md5 to generate a totally random string
$md5 = md5(microtime() * mktime());
/*
We dont need a 32 character long string so we trim it down to 5
*/
$string = substr($md5,0,5);
/*
Now for the GD stuff, for ease of use lets create the image from a background image.
*/
$captcha = imagecreatefrompng("./captcha.png");
/*
Lets set the colours, the colour $line is used to generate lines.
Using a blue misty colours. The colour codes are in RGB
*/
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);
/*
Now to make it a little bit harder for any bots to break,
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
/*Now for the all important writing of the randomly generated string to the image.*/
imagestring($captcha, 5, 20, 10, $string, $black);
/*Encrypt and store the key inside of a session*/
$_SESSION['key'] = md5($string);
/*Output the image*/
header("Content-type: image/png");
imagepng($captcha);
}
elseif (!isset($_POST['u']))
{
echo "<html>";
echo "<head>";
echo "<title>GD Test</title>";
echo "</head>";
echo "<body>";
echo "<img src=\"imgcode.php?image=1\">";
echo "<form method=\"post\" action=\"imgcode.php\">";
echo "<input type=\"text\" name=\"code\" value=\"\">";
echo "<input type=\"submit\" value=\"Test\">";
echo "<input type=\"hidden\" name=\"u\">";
echo "</form>";
echo "</body>";
echo "</html>";
}
?>
<?
session_start();
//Encrypt the posted code field and then compare with the stored key
if(md5($_POST['code']) != $_SESSION['key'])
{
die("Error: You must enter the code correctly");
}else{
echo 'You entered the code correctly';
}
?>

westmatrix99
03-03-2007, 05:28 PM
COOL FIXED COOL.

BONUS!!!
THANKS DUDE OR DUDETTE!!!



<?php
if ($_GET['image']==1)
{
//Start the session so we can store what the code actually is.
session_start();
//Now lets use md5 to generate a totally random string
$md5 = md5(microtime() * mktime());
/*
We dont need a 32 character long string so we trim it down to 5
*/
$string = substr($md5,0,5);
/*
Now for the GD stuff, for ease of use lets create the image from a background image.
*/
$captcha = imagecreatefrompng("./captcha.png");
/*
Lets set the colours, the colour $line is used to generate lines.
Using a blue misty colours. The colour codes are in RGB
*/
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);
/*
Now to make it a little bit harder for any bots to break,
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
/*Now for the all important writing of the randomly generated string to the image.*/
imagestring($captcha, 5, 20, 10, $string, $black);
/*Encrypt and store the key inside of a session*/
$_SESSION['key'] = md5($string);
/*Output the image*/
header("Content-type: image/png");
imagepng($captcha);
}
elseif (!isset($_POST['u']))
{
echo "<html>";
echo "<head>";
echo "<title>GD Test</title>";
echo "</head>";
echo "<body>";
echo "<img src=\"imgcode.php?image=1\">";
echo "<form method=\"post\" action=\"imgcode.php\">";
echo "<input type=\"text\" name=\"code\" value=\"\">";
echo "<input type=\"submit\" value=\"Test\">";
echo "<input type=\"hidden\" name=\"u\">";
echo "</form>";
echo "</body>";
echo "</html>";
}
elseif (isset($_POST['code']))
{
session_start();
//Encrypt the posted code field and then compare with the stored key
if(md5($_POST['code']) != $_SESSION['key'])
{
die("Error: You must enter the code correctly");
}else{
echo 'You entered the code correctly';
}
}
?>

rafiki
03-03-2007, 08:05 PM
<?php
//Start the session
session_start();

//make random string do not edit
$md5 = md5(microtime() * mktime());


// strip the 32 char string to 5 char
/$str = substr($md5,0,5);
//Have the image for background premade
$capt = imagecreatefrompng("./captcha.png");

//set colours
$black = imagecolorallocate($capt, 0, 0, 0);
$line = imagecolorallocate($capt,233,239,239);
//DONT EDIT THESE LINES
//ANTI BOTS
imageline($capt,0,0,39,29,$line);
imageline($capt,40,0,64,29,$line);
//end anti bot

imagestring($capt, 5, 20, 10, $str, $black);

$_SESSION['key'] = md5($str);

//heres the image
header("Content-type: image/png");
imagepng($capt);
?>
//thats one page
//now check the info inputted

<?php

session_start();

if(md5($_POST['code']) != $_SESSION['key'])
{
die("Error: You must enter the code correctly"); //code for incorrect input
}else{
echo 'You entered the code correctly'; //code for correct input
}
?> think that works
to make CFM happy i removed copyright!

westmatrix99
03-03-2007, 08:19 PM
Where is the form?

CFMaBiSmAd
03-03-2007, 08:22 PM
The code that westmatrix99 used comes from this Tutorial - http://codewalkers.com/tutorials/95/1.html, which claims to have a publish date of June 6, 2006

westmatrix99
03-04-2007, 07:22 AM
CFMaBiSmAd
What has that got to do with the previous posts?

CFMaBiSmAd
03-04-2007, 01:55 PM
The code that rafiki posted is identical, except for a few comment lines, but claims to be copyrighted 2007 by an organization and contributed by an author that is different than the 2006 tutorial on codewalkers. The web site that claims a copyright on this is just a generic script repository and it and the purported author probably do not have the right to claim it as their own code.

rafiki
03-04-2007, 02:44 PM
The code that rafiki posted is identical, except for a few comment lines, but claims to be copyrighted 2007 by an organization and contributed by an author that is different than the 2006 tutorial on codewalkers. The web site that claims a copyright on this is just a generic script repository and it and the purported author probably do not have the right to claim it as their own code.
i made that code myself and didnt copy any site, some one on msn asked me to make them it specifically that way, and theform you can handle yourself

westmatrix99
03-04-2007, 04:47 PM
I know, who in their right mind claims to copyright a code that is supposed to be a free script all around the world - sorry can't and wont believe that.

That means that I or anyone else can copyright the PHP creation and or that I or anyone else founded PHP or some crap similar.

Check yourself and your ideas of what you think you own.

rafiki
03-04-2007, 05:08 PM
I know, who in their right mind claims to copyright a code that is supposed to be a free script all around the world - sorry can't and wont believe that.

That means that I or anyone else can copyright the PHP creation and or that I or anyone else founded PHP or some crap similar.

Check yourself and your ideas of what you think you own.
are you thick? i made the script for a friend! i made it i own it,

westmatrix99
03-04-2007, 05:15 PM
If I am thick then everybody that does not beleive you is thick or maybe we are not as rude as you are.

If it's yours why are you getting so upset about it; let it go...

CFMaBiSmAd
03-04-2007, 05:26 PM
Codewalkers is one of the popular PHP language sites. You should probably contact them and at least get mentioned in the tutorial as the author of the code it contains.

westmatrix99
03-04-2007, 05:28 PM
Did already.

Waiting for response.

amwalsh
03-04-2007, 09:44 PM
I am the author of the tutorial at codewalkers.com, and i can confirm that i wrote this code on this tutorial with the assistance of only the PHP manual and a Pocket PHP Reference for looking up the usage of certain functions. If you wish to contact me at codewalkers then drop a PM to the user Andrew.

Thank you

Andrew Walsh

westmatrix99
03-05-2007, 05:28 AM
Thanks Andrew

Cheers
West

neomaximus2k
03-05-2007, 09:17 PM
Sorry my machine has been down for a while, glad to see you managed to port the script to windows even if it is much longer :S

For people who want to see the GD script in action then visit
http://www.paramiliar.com/articles.php?groupid=1&group=Search%20Engine%20Optimisation

At the bottom you will see the CAPTCHA code in action.


finally I found the way...
please check it out! :thumbsup:



<?php

if ($_GET['image']==1)
{
session_start();

$thecode;
session_register('thecode');

$alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

$rand = substr(str_shuffle($alphanum), 0, 5);
$rand = substr(md5($rand), 0, 5);

$bgNum = rand(1, 3);

$font = "c:/windows/fonts/arial.ttf";

$image = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT']."/ikc/bg".$bgNum.".jpg");
$textColor = imagecolorallocate ($image, 82, 82, 82);

$rand = substr(str_shuffle($alphanum), 0, 5);
$rand1 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand2 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand3 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand4 = strtoupper(substr(md5($rand), 0, 1));
$rand = substr(str_shuffle($alphanum), 0, 5);
$rand5 = strtoupper(substr(md5($rand), 0, 1));

$thecode = $rand1.$rand2.$rand3.$rand4.$rand5;

imagettftext($image, 18, rand(-12, 12), 7, 26, $textColor, $font, $rand1);
imagettftext($image, 18, rand(-12, 12), 29, 31, $textColor, $font, $rand2);
imagettftext($image, 18, rand(-12, 12), 41, 21, $textColor, $font, $rand3);
imagettftext($image, 18, rand(-12, 12), 66, 24, $textColor, $font, $rand4);
imagettftext($image, 18, rand(-12, 12), 86, 33, $textColor, $font, $rand5);

$_SESSION['paramil_verification'] = $thecode;

header('Content-type: image/jpeg');

imagejpeg($image);

$_SESSION['ns'] = $thecode;

imagedestroy($image);
}

elseif (!isset($_POST['u']))
{
echo "<html>";
echo "<head>";
echo "<title>GD Test</title>";
echo "</head>";
echo "<body>";
echo "<img src=\"gdcode.php?image=1\">";
echo "<form method=\"post\" action=\"gdcode.php\">";
echo "<input type=\"text\" name=\"random\" value=\"\">";
echo "<input type=\"submit\" value=\"Test\">";
echo "<input type=\"hidden\" name=\"u\">";
echo "</form>";
echo "</body>";
echo "</html>";
}

elseif (isset($_POST['random']))
{
session_start();

$random = $_POST['random'];
$random = trim($random);

if ($_SESSION['ns'] == $random)
{
echo "You are verified!";
$_SESSION['vf'] = "yup";
}

else
{
echo "Wrong code! Please go back and get verified.";
$_SESSION['vf'] = "hn";
}

}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum