Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there anyway to make URL forbidden to access from php file without "touching" (configure) the webserver??
Posted

1 solution

If you use an Apache Webserver, you can create a .htaccess file and add this code inside it:
none
<Files forbiddenfile.php>
Order Deny,Allow
Deny from All
</Files>

ErrorDocument 403 /ErrorPages/403.php

If you find that this is configuring the server, you can also redirect the user to the 403 page if he tries to access forbiddenfile.php:
PHP
<?php
header('Location: /ErrorPages/403.php'); // add this PHP code at the top of your PHP file
?>  

Hope this helps.
 
Share this answer
 
Comments
Taftazani 26-Aug-13 15:47pm    
Thanks it works...
If I may,,one more question please...

I tried to load this forbidden file with iframe inside somepage.php..So when I login how to make :
- if I type URL www.example.com/somesite/forbiddenfile.php, the response page will be forbidden file
- if I type URL www.example.com/somesite/somepage.php, the file forbiddenfile.php inside iframe will show something (not forbidden response)

I have tried whatever method came to my mind but the somepage.php iframe still show forbidden response...
any idea to solve this?? Please..
Thomas Daniels 27-Aug-13 2:49am    
I would suggest to create another file instead of using forbiddenfile.php.
Taftazani 30-Aug-13 2:43am    
If I make another file, isn't it still can be access through the URL from browser??
Thomas Daniels 30-Aug-13 2:56am    
Yes, but if you make a file forbidden, then it is also forbidden in the iframe!
Try this: create another file, and add the contents which should be visible in the iframe into it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900