Friday, April 13, 2007

md5 Checking

<html>
<head><title>Muntenari.Com: md5 Checking</title>
</head>
<body>
String:
<form action=? method=post>
<input type=text name=str>
<input type=submit value=Submit>
</form>
<p>
<?
if($_POST['str']) echo "md5('".$_POST['str']."') : ".md5($_POST['str']);
?>
</body>
</html>

To try the script above please visit http://muntenari.com/exercise/md5.php

Thursday, April 12, 2007

Fatal error: Call to undefined function: imagecreatetruecolor

Here is the solution.

1. Open php.ini file.
2. Enable extension=php_gd2.dll by deleting semicolon ';'

Create Random String Image

<?

$string = stringGenerator();
//setcookie("ivstrcookie", $string, time()+3600);

function imageGenerator($string) {
header("Content-type: image/png");

$x = 100;
$y = 30;
$im = imagecreatetruecolor($x,$y);
$putih = imagecolorallocate($im, 255, 255, 255);
$orange = imagecolorallocate($im, 220, 210, 60);
$hitam = imagecolorallocate($im, 0, 0, 0);
$abu2 = imagecolorallocate($im, 200, 200, 200);
imagefill($im,0,0,$putih);
// Border
imagerectangle($im,0,0,$x-1,$y-1,$hitam);

imagestring($im, 6, $x - 78, $y - 24, $string, $hitam);

imagepng($im);
imagedestroy($im);
}

function stringGenerator() {
$strlen = 6;
$string = '';
for ($i=1;$i<=$strlen;$i++) {
$rand2 = round(rand (0, 2)) + 1;

if ($rand2 == 1) {
$bottomlimit = 48;
$toplimit = 57;
}
elseif ($rand2 == 2) {
$bottomlimit = 65;
$toplimit = 90;
}
else {
$bottomlimit = 97;
$toplimit = 122;
}

$rand1 = round(rand (0,$toplimit-$bottomlimit)) + $bottomlimit;
$string .= chr($rand1);
}

return $string;
}

imageGenerator($string);
?>

Save as image.php. Example available at http://muntenari.com/imageverification.php