简体   繁体   中英

Redirection on direct access to PHP script

I'm building a website that contains a considerable amount of object-oriented PHP code. 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. Being a form evaluation script, it already has redirections based on the POST variable to prevent dummy execution and database errors.

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 ?

you can either

  • put it outside the public_html folder
  • deny access/redirect using filename patterns in the .htaccess
  • build a small php code in (the top of every class file) that looks for a variable which is initialised in the index. If it's not there, redirect.

If you need further explanation on any of these, just ask.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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