Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplay captcha that is outside of root
    primarykey
    data
    text
    <p>I can not display <code>captcha</code> that is outside of root in my shared server. My <code>html</code> page:</p> <pre><code>&lt;img align="top" id="captcha" src="&lt;?=ROOT_PATH.$this-&gt;editPath;?&gt;function/security_code.php?&lt;?=mt_rand(100, 9999);?&gt;" /&gt; </code></pre> <p>it work fine in <code>localhost</code>.<br> and <code>security_code.php</code> is :</p> <pre><code>header('Content-Type: image/jpeg'); session_start(); class captchaGD { public $font='arial.ttf'; public function generateCode($characters) { $possible = '23456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ'; $code = ''; $i = 0; while ($i &lt; $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function __construct($width='120',$height='40',$characters='6') { $code = $this-&gt;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&lt;($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); for( $i=0; $i&lt;($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-&gt;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-&gt;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']); </code></pre> <hr> <p><strong>Edit</strong>: According to comment, does it work fine If i put <code>security_code.php</code> in <code>public_html</code>? is it safe way?What better way to do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload