0

我无法captcha在我的共享服务器中显示根目录之外的内容。我的html页面:

<img align="top" id="captcha" src="<?=ROOT_PATH.$this->editPath;?>function/security_code.php?<?=mt_rand(100, 9999);?>" />

它工作正常localhost
并且security_code.php是:

header('Content-Type: image/jpeg');
session_start();
class captchaGD {   
public $font='arial.ttf';
public function generateCode($characters) {
    $possible = '23456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ';
    $code = '';
    $i = 0;
    while ($i < $characters) {
        $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
        $i++;
    }
    return $code;
}
function __construct($width='120',$height='40',$characters='6') {
    $code = $this->generateCode($characters);
    $font_size = $height * 0.5;
    $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
    $background_color = imagecolorallocate($image, 255, 255, 255);
    $text_color = imagecolorallocate($image, 20, 40, 100);
    $noise_color = imagecolorallocate($image, 100, 120, 180);
    for( $i=0; $i<($width*$height)/3; $i++ ) {
        imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
    for( $i=0; $i<($width*$height)/200; $i++ ) {
        imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
    }
    $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');
    imagejpeg($image); 
    imagedestroy($image);
        $_SESSION['security_code']['form']="";
        $_SESSION['security_code']['form'] = strtolower($code); 
}
}
$width =  '120';
$height = '40';
$characters = '3';
$captcha = new captchaGD($width,$height,$characters,$_SERVER['REQUEST_URI']);

编辑:根据评论,如果我放进去,它工作正常security_code.phppublic_html?这是安全的方式吗?有什么更好的方法来做到这一点?

4

1 回答 1

0

您需要提供外部可访问地址/域而不是

<?=ROOT_PATH.$this->editPath;?>

就像是

$mydomain = 'http://www.yourdomain.com';
<?=$mydomain;?>function/security_code.php?<?=mt_rand(100, 9999);?>

恕我直言。href 就是这样工作的。

于 2013-08-29T15:32:21.730 回答