Jump to content


include file extensions

  • Please log in to reply
3 replies to this topic

#1 completeamateur

  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 03 April 2006 - 08:57 PM

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.

#2 ToonMariner

  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 03 April 2006 - 10:25 PM

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.
follow me on twitter @PHPsycho

#3 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 April 2006 - 11:11 AM

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.

#4 completeamateur

  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 05 April 2006 - 11:29 PM

Cheers guys, I wouldn't have thought about exposing code when not using ".php".

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users