1

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?

5
  • 3
    put it outside of your publicly accessible folder Commented Apr 6, 2014 at 23:00
  • I had that in mind, however due to organisation I would like a PHP solution, not a server workaround. Commented Apr 6, 2014 at 23:03
  • 2
    "server workaround" or just the best approach? Commented Apr 6, 2014 at 23:04
  • 2
    i wouldn't call putting it in a folder outside your public folder a workaround. I'd call it a best practice. I'd call your desired php solution the workaround Commented Apr 6, 2014 at 23:05
  • I guess it is. I'll just stick with that then. Thanks Commented Apr 6, 2014 at 23:06

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It seems my original way is the worst option, though, given the useless processing power spent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.