我正在使用一個簡單的驗證碼系統的窗體。在Windows上運行良好,但不在Mac上顯示。在兩個系統中啓用DG,我已經檢查過phpinfo()。php GD captcha圖像不顯示在Mac上
<?php
session_start();
// generate random number and store in session
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
//generate image
$im = imagecreatetruecolor(90, 32);
//colors:
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 35, $black);
//path to font:
$font = 'fonts/rock-webfont.ttf';
//draw text:
//imagettftext($im, 35, 0, 22, 24, $grey, $font, $randomnr);
//imagettftext($im, 35, 0, 15, 26, $white, $font, $randomnr);
imagettftext($im, 24, 0, 12, 26, $grey, $font, $randomnr);
imagettftext($im, 24, 0, 8, 28, $white, $font, $randomnr);
// 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/gif");
imagegif($im);
imagedestroy($im);
?>
更新:我使用安裝了PHP 5.3.3版的OS X Snow Leopard。我現在啓用了錯誤報告,我看到這個錯誤:調用未定義函數imagettftext()。這很奇怪,因爲如果我導航到函數的定義,它會將我帶到GD庫中的imagettftext()!
有什麼建議嗎?
在此先感謝。
莫羅
加入使用error_reporting(E_ALL); ini_set('display_errors','On');在您的PHP腳本的開頭,查看可能的錯誤。我看到兩個可能的問題:它無法找到字體文件或標題的東西使Windows上的問題 – strauberry 2011-05-13 09:28:52
你是什麼意思「在Mac上」?在Mac服務器上?在Mac瀏覽器上?如果您嘗試直接訪問CAPTCHA圖像會發生什麼情況,您會得到什麼信息? – 2011-05-13 09:28:55
@strauberry我添加了錯誤報告,我得到了這個:致命錯誤:調用未定義函數imagettftext()在/Users/.../captcha.php在第26行。什麼樣的錯誤是?我如何解決它?謝謝 – Mauro74 2011-05-13 09:33:19