Hi,

I hope to get some good explanations on the site about pros & cons of using .inc files (header.inc, footer.inc, etc.) in PHP instead of .php files.

I saw a site that the developer didn't use "include()" in the codes. So I assumed that it has to be in the configuration file that is set "auto_prepend_file" or "auto_append_file" to the path where the include files are.

Any good explanation to help me figure that out what the best way for me to manage files in OOP way?

Thanks, guys!

    Con;

    Some servers wont recognise these files as PHP files so if somebody managed to browse to them they would see the code rather than the result of the execution.

    Pros;

    There isn't really any, it behaves the same... just a different file name.

    OOP page layout and ccontrol would be best with a temlating system. And use of the __autoload function.

      There are a few pros to using .inc files in your application. For starters, it could be easier for you to know from the file-name whether or not the file is reached via the URL or if it's included without having to open it. Secondly, it gives you an easy way to group files together.

      On the other hand, .inc files are typically served up as plain/text on 99.9% of servers. So if someone found out the name of the include file, you'd be screwed if you kept your database information (or worse yet, FTP info) in there. So that's a downside. The other downside is that it's an old way to do things. That doesn't sound like a bad thing, but if you're moving to OOP, you may as well get rid of your old ways all together.

      As Dougal said, use the __autoload method of the class to load whatever files you need. Typically, these included files are kept in their own folder (aptly named "includes" in many projects) so they're grouped together and easier to maintain.

      You could use the convention of "filename.inc.php" or "inc.fielname.php" so that you still have "inc" in the filename, it's just that instead of seeing the plain/text content of the file, they'll now see a blank page since PHP won't output anything, or they see an error stating that something isn't right (like no database connection, or missing variables or classes).

        Write a Reply...