256MB |
Im trying to put a captcha image in my site to stop people from spamming, and when i view the image its self i get this: Fatal error: Call to undefined function imagettfbbox() in (...)/htdocs/CaptchaSecurityImages.php on line 39
so heres my code:
[php]
<?php
session_start();
class CaptchaSecurityImages {
var $font = 'monofont.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$c haracters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
[/php]
i hope you guys can help, im lost!
| |
Share:
Expert 1GB |
You are calling a function that doesn't exist here
[PHP]$textbox = imagettfbbox($font_size, 0, $this->font, $code)[/PHP]
Is the function a member function?
If so you need to call it as such
[PHP]$textbox = $this->imagettfbbox($font_size, 0, $this->font, $code)[/PHP]
| | 256MB |
i changed that part of the code
Fatal error: Call to undefined method CaptchaSecurityImages::imagettfbbox() in /www/110mb.com/p/l/a/y/e/r/-/k/player-killer-clan/htdocs/CaptchaSecurityImages.php on line 39
now i get that...
or can you suggest another form of making a captcha?
| | |
Your code above should work.. Just make sure that your font and CaptchaSecurityImages.php are in the same directory. Also make sure you have the GD library turned on as well. To include it in your form just use: -
<img src="CaptchaSecurityImages.php?width=160&height=80&characters=5" alt="captcha" />
-
In this example the CaptchaSecurityImages.php is in the same directory as the files that host your form. The width, height and the number of characters are up to you to decide. I'm really not sure where you are calling imagettfbbox() and I don't think you have to make your Captcha work.
Let me know if this works.
| | |
O wait your code should look something like this: -
-
-
function generateCode($characters) {
-
/* list all possible characters, similar looking characters and vowels have been removed */
-
$possible = '23456789bcdfghjkmnpqrstvwxyz';
-
$code = '';
-
$i = 0;
-
while ($i < $characters) {
-
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
-
$i++;
-
}
-
return $code;
-
-
}
-
-
function CaptchaSecurityImages($width='160',$height='80',$characters='5') {
-
$code = $this->generateCode($characters);
-
/* font size will be 45% of the image height */
-
$font_size = $height * 0.45;
-
$image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
-
/* set the colours */
-
$background_color = imagecolorallocate($image, 255, 255, 255);
-
$text_color = imagecolorallocate($image, 20, 40, 100);
-
$noise_color = imagecolorallocate($image, 100, 120, 180);
-
/* generate random dots in background */
-
for( $i=0; $i<($width*$height)/3; $i++ ) {
-
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
-
}
-
/* generate random lines in background */
-
for( $i=0; $i<($width*$height)/150; $i++ ) {
-
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
-
}
-
/* create textbox and add text */
-
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
-
$x = ($width - $textbox[4])/2;
-
$y = ($height - $textbox[5])/2;
-
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
-
/* output captcha image to browser */
-
$_SESSION['code'] = $code;
-
header('Content-Type: image/jpeg');
-
imagejpeg($image);
-
imagedestroy($image);
-
-
-
}
-
-
}
-
-
$width = isset($_GET['width']) && $_GET['height'] < 600 ? $_GET['width'] : '120';
-
$height = isset($_GET['height']) && $_GET['height'] < 200 ? $_GET['height'] : '40';
-
$characters = isset($_GET['characters']) && $_GET['characters'] > 2 ? $_GET['characters'] : '6';
-
-
$captcha = new CaptchaSecurityImages($width,$height,$characters);
-
This should work. Again let me know.
| | 256MB |
Fatal error: Class 'CaptchaSecurityImages' not found in /www/110mb.com/p/l/a/y/e/r/-/k/player-killer-clan/htdocs/CaptchaSecurityImages.php on line 50
with
[php]
<?php
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='160',$height='80',$c haracters='5') {
$code = $this->generateCode($characters);
/* font size will be 45% of the image height */
$font_size = $height * 0.45;
$image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
$_SESSION['code'] = $code;
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
}
$width = isset($_GET['width']) && $_GET['height'] < 600 ? $_GET['width'] : '120';
$height = isset($_GET['height']) && $_GET['height'] < 200 ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 2 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
[/php]
| | 256MB |
im using this captcha now:
http://www.mindpalette.com/tutorials/captcha/connect.php
and it tells how to connect it ot these specila form thingamaboblets, but it doesn't say how to conneft it with my ismple if-then-else form validator. unless it does and im missing it. oh well, i need sleep, if anybody finds it could you be so kind as to share?
thanks :)
| | |
I had the same error.
I changed: "var $font = 'monofont.ttf';"
to "var $font = './monofont.ttf';"
and it worked.
I hate this types of errors ;-)...
| | |
Thank you very much Mike... It helps me a lot
| | |
It works great. This helps a lot.
| | 2Bits |
I am facing the same problem too, with the same code. I lost the procedure that I had done once before, had kept the steps in a txt file, and have forgotten what I had done. Now ever since I re-installed my Xampp, this is the issue taking place in the same version on my laptop, whereas in my PC it is working fine. Though I followed the instructions above, nothing seem to work. Can somebody help me out? Does the PHP.INI file needs to be fiddled with? or does this have anything to do with .htaccess file?
| | 2Bits |
The error is in the file php_gd2.dll. This file is located in: xampp/php/ext/php_gd2.dll. If I copy my older file from my PC to the laptop newly installed 32 bit xampp on windows 10 64bit, then the captcha and everything appears without any problem. But now the question is how to solve the xampp 8.0 64bit problem? there the file is php_gd.dll? Any solution to this file?
| | Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
9 posts
views
Thread by Mairhtin O'Feannag |
last post: by
|
13 posts
views
Thread by deko |
last post: by
|
6 posts
views
Thread by Peter Frost |
last post: by
|
15 posts
views
Thread by David Lozzi |
last post: by
|
33 posts
views
Thread by Anthony England |
last post: by
|
1 post
views
Thread by developer |
last post: by
|
2 posts
views
Thread by f rom |
last post: by
| |
2 posts
views
Thread by laredotornado |
last post: by
| | | | | | | | | | |