catania
09-11-2011, 02:22 AM
Hi,
I'm trying to implement a captcha code. This is working fine:
<?php
function imagen() {
header("Content-type: image/png");
$img = imagecreatetruecolor(240,60);
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$grey = imagecolorallocate($img, 150, 150, 150);
$pink = imagecolorallocate($img, 200, 0, 150);
$font = "./erasbd.ttf";
imagefill($img, 0, 0, $grey);
$string = random_string(rand(7,8));
imagettftext($img, 26, 5, 13, 45, $black, $font, $string);
imagettftext($img, 26, 5, 15, 47, $pink, $font, $string);
imagettftext($img, 26, 3, 18, 49, $white, $font, $string);
$imagen = imagepng($img);
$fin_magine = imagedestroy($img);
if(isset($_FILES[$imagen][$fin_magine])) {
echo $imagen; $fin_magine;
} else {
}
}
imagen();
?>
but when trying to use it inside html it will return: The image “http://........./captcha3.php” cannot be displayed because it contains errors.
here's how I placed it
table
tr
td <?php
function imagen() {
header("Content-type: image/png");
$img = imagecreatetruecolor(240,60);
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$grey = imagecolorallocate($img, 150, 150, 150);
$pink = imagecolorallocate($img, 200, 0, 150);
$font = "./erasbd";
imagefill($img, 0, 0, $grey);
$string = random_string(rand(7,8));
imagettftext($img, 26, 5, 13, 45, $black, $font, $string);
imagettftext($img, 26, 5, 15, 47, $pink, $font, $string);
imagettftext($img, 26, 3, 18, 49, $white, $font, $string);
$imagen = imagepng($img);
$fin_magine = imagedestroy($img);
if(isset($_FILES[$imagen][$fin_magine])) {
echo $imagen; $fin_magine;
} else {
}
}
imagen();
?>
!-- <img src="captcha2.php" / --
/td
/td
td
form action"captcha.php" method"post"
input name="cambiar" type="submit" value="Cambiar"/
/td
tr
tdEscriba el codigo de la imagen que ve arriba/td
/tr
tr
td <input id="captcha" name="captcha" type="text"/
/td
/tr
as you can see i commented out <img src="captcha2.php" which I innitially tried but y idea is to place it as a function so I can validate that with the imput value. Please let me know if there's any solution.
Most appreciated!
Carlos
I'm trying to implement a captcha code. This is working fine:
<?php
function imagen() {
header("Content-type: image/png");
$img = imagecreatetruecolor(240,60);
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$grey = imagecolorallocate($img, 150, 150, 150);
$pink = imagecolorallocate($img, 200, 0, 150);
$font = "./erasbd.ttf";
imagefill($img, 0, 0, $grey);
$string = random_string(rand(7,8));
imagettftext($img, 26, 5, 13, 45, $black, $font, $string);
imagettftext($img, 26, 5, 15, 47, $pink, $font, $string);
imagettftext($img, 26, 3, 18, 49, $white, $font, $string);
$imagen = imagepng($img);
$fin_magine = imagedestroy($img);
if(isset($_FILES[$imagen][$fin_magine])) {
echo $imagen; $fin_magine;
} else {
}
}
imagen();
?>
but when trying to use it inside html it will return: The image “http://........./captcha3.php” cannot be displayed because it contains errors.
here's how I placed it
table
tr
td <?php
function imagen() {
header("Content-type: image/png");
$img = imagecreatetruecolor(240,60);
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$grey = imagecolorallocate($img, 150, 150, 150);
$pink = imagecolorallocate($img, 200, 0, 150);
$font = "./erasbd";
imagefill($img, 0, 0, $grey);
$string = random_string(rand(7,8));
imagettftext($img, 26, 5, 13, 45, $black, $font, $string);
imagettftext($img, 26, 5, 15, 47, $pink, $font, $string);
imagettftext($img, 26, 3, 18, 49, $white, $font, $string);
$imagen = imagepng($img);
$fin_magine = imagedestroy($img);
if(isset($_FILES[$imagen][$fin_magine])) {
echo $imagen; $fin_magine;
} else {
}
}
imagen();
?>
!-- <img src="captcha2.php" / --
/td
/td
td
form action"captcha.php" method"post"
input name="cambiar" type="submit" value="Cambiar"/
/td
tr
tdEscriba el codigo de la imagen que ve arriba/td
/tr
tr
td <input id="captcha" name="captcha" type="text"/
/td
/tr
as you can see i commented out <img src="captcha2.php" which I innitially tried but y idea is to place it as a function so I can validate that with the imput value. Please let me know if there's any solution.
Most appreciated!
Carlos