Asked  7 Months ago    Answers:  5   Viewed   52 times

Why am I getting the error PHP Fatal error: Call to undefined function imagettftext() on line 29?

<?php
ob_start();
session_start();

$strings = '123456789';
$i = 0;
$characters = 6;
$code = '';
while ($i < $characters)
{ 
    $code .= substr($strings, mt_rand(0, strlen($strings)-1), 1);
    $i++;
} 

$_SESSION['captcha'] = $code;

//generate image
$im = imagecreatetruecolor(124, 40);
$foreground = imagecolorallocate($im, 0, 0, 0);
$shadow = imagecolorallocate($im, 173, 172, 168);
$background = imagecolorallocate($im, 255, 255, 255);

imagefilledrectangle($im, 0, 0, 200, 200, $background);

// use your own font!
$font = 'monofont.ttf';

//draw text:
imagettftext($im, 35, 0, 9, 28, $shadow, $font, $code);
imagettftext($im, 35, 0, 2, 32, $foreground, $font, $code);     

// prevent client side  caching
header("Expires: Wed, 1 Jan 1997 00: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 image to browser
header ("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>`

My PHP Info:

enter image description here

enter image description here

 Answers

21

According to the PHP manual entry for imagettftext():

This function requires both the GD library and the ยป FreeType library.

You must be missing one or both of the required libraries in your PHP build.

Wednesday, March 31, 2021
 
Zeth
answered 7 Months ago
37

Call to undefined function error clearly shows that its not getting your function where you have defined. Reason is you are attaching full path of settings.php file with http.

You need to include settings.php file without http path at the top of 'index.php' and make sure settings.php file is located in your project only. If it is located at the same folder with index.php, then simply include like below.

<?php include 'settings.php'; ?> 

If your settings.php file is located in some other website but in your same server then you can use $_SERVER['DOCUMENT_ROOT'] to include that file like below:

<?php 
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/yourpath/settings.php";
include_once($path);
?>

If your settings.php file is located in some other website and some other server then you need to update allow_url_include=On in your php.ini that is the MAJOR SECURITY RISK. So, if you trust the website then only do it.

// Extremely insecure:
<?php include("http://sub.website.com/incl/Settings.php"); ?>
Wednesday, March 31, 2021
 
alioygur
answered 7 Months ago
79

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
 
Nate
answered 5 Months ago
90

If the image it is returning is a valid file, then I would recommend running the scrape twice (ie. download it twice and check to see if they are the same).

Another option would be to check the last few pixels of the image (ie. bottom-right corner) to see if they match that color of grey exactly. If they do, then redownload. (obviously this approach fails if you download an image that is actually supposed to be grey in that corner, in that exact colour...but if you check several of the last pixels it should reduce the chance of that to an acceptable level).

Thursday, July 29, 2021
 
ranhan
answered 3 Months ago
26

The problem was the wrong permissions for the /etc/phpMyAdmin directory. The web server user, apache, had proper permissions for the session.save_path directory, but apache couldn't read from my config.inc.php file. Changing the owner of /etc/phpMyAdmin to the apache user and changing the permissions to 755 solved the problem.

Looking at the checkConfigSource() function in Config.class.php led me to believe that if the problem was with accessing the configuration file then I would have received the error 'Existing configuration file (%s) is not readable.' instead of Call to undefined function __() Does anyone know why that wasn't the case?

This was a pretty basic problem/solution, but unless someone suggests otherwise I think I'll leave it up since this exact problem/solution isn't addressed in other discussions of the Fatal error: Call to undefined function __() in /usr/share/phpMyAdmin/libraries/core.lib.php error when trying to start phpMyAdmin after installation.

Saturday, July 31, 2021
 
Simmeringc
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :