Jump to content

Archived

This topic is now archived and is closed to further replies.

completeamateur

include file extensions

Recommended Posts

Just a couple of q's regarding include files...

1. Can I give them any extension I want? What is the best (.php .inc .txt)?

2. Does it matter if I have loads of includes in one page. I plan to have a template with 7 different include files (albeit small) to make maintenance/content easier to manage.

Thanks in advance.

Share this post


Link to post
Share on other sites
it doesn'y matter what extension you give anyfile in an include statement.

But bear in mind the file is treated as plain text so if you want to include more php code the included file must be a valid stand alone script (it must have the <?php and ?> tags in there.)

You can include as many things as you like - but have a look at using include_once and the require equivalents also they can really help especially in big files when you are not sure what you have or have not included yet.

Be sure to refrain from having paths to includes being generated from user input. If it is absolutely neccessary use $_SERVER['DOCUMENT_ROOT'] at the start of the path - this will prevent them from including files on another server which could easily breach your own security.

Share this post


Link to post
Share on other sites
You can use any extension you like but allweasy save your files that get included with .php extensions otherise any other file such as .html, .txt, .inc will treat your PHP code as normal text and so a user can see your PHP Code! However you can use any extension you like for your files that get included as PHP will parse these as PHP with the parent script when they get included, just make sure you surrond your code blocks in PHP tags.

One tip I would recommend you to do is prehaps save your files as filename.inc.php so you can easily identify your files that get included from the normal .php files.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.