admin管理员组文章数量:1434388
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?
3 Answers
Reset to default 10Presumably 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>
本文标签: phpHow to prevent access to certain URL requested pagesStack Overflow
版权声明:本文标题:php - How to prevent access to certain URL requested pages? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745633545a2667415.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论