最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to prevent access to certain URL requested pages? - Stack Overflow

programmeradmin2浏览0评论

How to prevent access to certain URL requested pages?

If i have form.html, processFrom.php and getResults.php in my webapp root, even though processFrom.php does not echo any content, how can i prevent the user from accessing this file by typing in the URL?

How to prevent access to certain URL requested pages?

If i have form.html, processFrom.php and getResults.php in my webapp root, even though processFrom.php does not echo any content, how can i prevent the user from accessing this file by typing in the URL?

Share Improve this question asked Jun 6, 2009 at 21:09 BabikerBabiker 18.8k28 gold badges82 silver badges127 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 10

Presumably you only ever access it via an include statement, or similar? Your safest bet would be to put it elsewhere on your filesystem, and include it from there.

Anything that isn't served by the web server shouldn't be kept under the web root.

The existing answers assume that processForm.php contains only code, and is not the page specified in the "action" attribute of your form. In case this assumption is incorrect, I'll answer assuming you DO want this page to directly process the POST request generated by your form, but that you want to prevent anybody from accidentally or maliciously running code in this file.

In this case, you can't hide the file as remended. Instead, you could use a token that is created when the form is displayed, stored in a session variable, and also submitted with the form (<input type="hidden" ... />). Before doing any processing in processForm.php, you check that the token is present and matches the one in the session variable. Also, you should always sanitize all form input. There's no stopping somebody submitting whatever they want to your script as long as it's web accessible.

When you work with an Apache web server I would suggest to create a .htaccess file and deny the access the file.

These links should help you setup a .htaccess file of your needs.

http://httpd.apache/docs/2.2/mod/core.html#files

Example .htaccess:

<Files processFrom.php>
Order allow,deny
Deny from all
</Files>
发布评论

评论列表(0)

  1. 暂无评论