我无法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.php
吗public_html
?这是安全的方式吗?有什么更好的方法来做到这一点?