Hi,

I have some include files in my PHP project, for example, I am including the meta tag because it's all the same..

I want to ask what's the best extension to use for include files? is it .inc or .php?

Thanks,
Jassim

    One single thing to remember: if you require a file with some non-php extension, apache won't parse it as php, unless you add rules for it. But an included file shouldn't be under the doc-root anyway, so if this has any kind of impact at all, the question is not "which extension to choose", it's "where should I place my files".

    Other than that, let me retort with a question on my own: Should I name my background images .jpg or .backgrnd?

      In other words, as far as PHP is concerned, when you include a file via a local file system path, it doesn't matter at all what you call it. If for some odd reason you are including it via http, it will make a difference, depending on whether or not the target web server processes .php file (which the vast majority to these days).

      If you choose to use a .php extension but you don't want the include file to ever be accessed directly by a user, you can stick something like this at the beginning:

      <?php
      if(realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME')) {
        header("HTTP/1.0 404 Not Found");
        exit;
      }
      
      // rest of include file...
      
        Write a Reply...