Jump to content

include file extensions


completeamateur

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.
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.