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!
12 17751
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]
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.
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]
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.
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?
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mairhtin O'Feannag |
last post by:
Hello,
We have two machines we wish to use DPF. They are both RH ES 2.1, with
DB2 8.2.
I read the documentation CAREFULLY, and added the following line to my
db2nodes.cfg file :
1 egret 0
|
by: deko |
last post by:
I use this convention frequently:
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much...
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the...
|
by: Anthony England |
last post by:
I am considering general error handling routines and have written a sample
function to look up an ID in a table. The function returns True if it can
find the ID and create a recordset based on...
|
by: developer |
last post by:
Hi All
I have made a .NET project.
the files included are borland c++ files that i am migrate to VC++ .NET
I am using Microsoft Visual C++ .NET 2003.
the compilation goes through properly,...
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: ...
|
by: jk2l |
last post by:
Error 10 error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj
Error 11 error...
|
by: laredotornado |
last post by:
Hi,
I'm using php 4.4.4. Maybe I'm misreading the docs, but in the
imagettfbbox manual (http://us2.php.net/imagettfbbox), it says that
text coordinates are the same regardless of what the angle...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| |