user1725155 user1725155 - 1 year ago 84
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 ?


Answer Source

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\.)? [NC]
RewriteRule ^hellothere/captcha\.php$ - [NC,F,L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download