user1725155 user1725155 - 4 months ago 14
PHP Question

Create a unreadable PHP page for capthca

I'm using the cool-captcha for my registration form.
This is the Captcha generated picture code which I'm using inside my codes:

<img src="captcha.php" id="captcha" />


Anyone can directly go to "captcha.php" page and view the image. So my question is, is there anyway to disable the direct access or direct viewing of Captcha.php in browser ? I just want the Captcha.php can only be used to view inside the img source not in direct viewing by browsers. Is there anyway to do in php or htaccess file ?

Thanks

Answer

You could of course use .htaccess in the same manner as in preventing hotlinking of images

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$   
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule ^hellothere/captcha\.php$ - [NC,F,L]