2012-05-08 47 views
-1

我最近移動了我的網站的服務器。然而,驗證碼的功能(這是從captcha.php心不是工作。伊夫拉查權限,這一切似乎好,還有什麼可以去錯了嗎? The site網站移動後破解驗證碼

的驗證碼的形式是向底部。香港專業教育學院一種感覺,它的!簡單的東西我在想念

Captcha.php:

<?php 
//Start the session so we can store what the security code actually is 
session_start(); 

//Send a generated image to the browser 
create_image(); 
exit(); 

function create_image() 
{ 

    // Set the content-type 
    header("Content-type: image/jpg"); 

    // Create the image 
    $im = imagecreatetruecolor(100, 30); 

    // Create some colors 
    $white = imagecolorallocate($im, 255, 255, 255); 
    $grey = imagecolorallocate($im, 128, 128, 128); 
    $black = imagecolorallocate($im, 0, 0, 0); 
    imagefilledrectangle($im, 0, 0, 399, 29, $white); 

    // The text to draw 
    $text = $_SESSION["captcha"]; 
    // Replace path by your own font path 
    $font = 'caviardreams.ttf'; 

    // Add some shadow to the text 
    imagettftext($im, 15, 0, 11, 21, $grey, $font, $text); 

    // Add the text 
    imagettftext($im, 15, 0, 10, 20, $black, $font, $text); 

    // Using imagepng() results in clearer text compared with imagejpeg() 
    imagepng($im); 
    imagedestroy($im); 
} 

?> 

這裏是修復(添加$字體=真實路徑($字體);):

<?php 
//Start the session so we can store what the security code actually is 
session_start(); 

//Send a generated image to the browser 
create_image(); 
exit(); 

function create_image() 
{ 

    // Set the content-type 
    header("Content-type: image/jpg"); 

    // Create the image 
    $im = imagecreatetruecolor(100, 30); 

    // Create some colors 
    $white = imagecolorallocate($im, 255, 255, 255); 
    $grey = imagecolorallocate($im, 128, 128, 128); 
    $black = imagecolorallocate($im, 0, 0, 0); 
    imagefilledrectangle($im, 0, 0, 399, 29, $white); 

    // The text to draw 
    $text = $_SESSION["captcha"]; 
    // Replace path by your own font path 
    $font = 'caviardreams.ttf'; 
    $font = realpath($font); 

    // Add some shadow to the text 
    imagettftext($im, 15, 0, 11, 21, $grey, $font, $text); 

    // Add the text 
    imagettftext($im, 15, 0, 10, 20, $black, $font, $text); 

    // Using imagepng() results in clearer text compared with imagejpeg() 
    imagepng($im); 
    imagedestroy($im); 
} 

?> 
+1

新服務器是否有GD?我強烈建議實施類似reCaptcha的方法,以使您和用戶更輕鬆(因爲它具有內置的輔助功能)。 – MetalFrog

+2

你的[圖像生成腳本](http://www.edexec.co.uk/captcha.php)正在生產看起來是有效的PNG,所以我的錢是在服務器上有正確的字體(我假設它使用搖晃的文本來實現驗證碼測試)。 – halfer

+0

看看錯誤日誌後,它看起來是字體:[Tue May 08 18:24:28 2012] [error] [client 94.174.84.164] PHP Warning:imagettftext():找不到/打開字體在/var/www/vhosts/intelligentmedia.co.uk/edexec/captcha.php 33行,referer:http://www.edexec.co.uk/subscribe/然而,字體在那裏,有644個權限.. – itsdanprice

回答

1

我想它需要PHP有GD installed,但是如果不知道服務器在嘗試渲染驗證碼時遇到的錯誤,就不可能知道。檢查你的日誌。