简体   繁体   English

直接访问PHP脚本的重定向

[英]Redirection on direct access to PHP script

I'm building a website that contains a considerable amount of object-oriented PHP code. 我正在构建一个包含大量面向对象的PHP代码的网站。 To keep the code clean, each class is stored in a single file named [classname].class.php and require_once 'd in the script file. 为了保持代码清洁,每个类都存储在脚本文件中名为[classname].class.phprequire_once的单个文件中。 Being a form evaluation script, it already has redirections based on the POST variable to prevent dummy execution and database errors. 作为表单评估脚本,它已经具有基于POST变量的重定向,以防止虚拟执行和数据库错误。

How do I make it so anyone trying to access the .class.php files gets redirected to the related HTML page, but keep it usable by include and require ? 我怎么做到这一点,所以任何试图访问.class.php文件的人都被重定向到相关的HTML页面,但是通过includerequire让它可用?

you can either 你也可以

  • put it outside the public_html folder 把它放在public_html文件夹之外
  • deny access/redirect using filename patterns in the .htaccess 使用.htaccess中的文件名模式拒绝访问/重定向
  • build a small php code in (the top of every class file) that looks for a variable which is initialised in the index. 在(每个类文件的顶部)构建一个小的PHP代码,用于查找在索引中初始化的变量。 If it's not there, redirect. 如果它不在那里,重定向。

If you need further explanation on any of these, just ask. 如果您需要进一步解释这些,请询问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM