vdegenne
vdegenne

Reputation: 13270

Is the php file extension needed for importation?

I wonder if I need to use ".php" for the php snippet files I must include in my principal page with include_once(...). When included in my code those snippets are handled as php instructions I guess so, then can we avoid the extension (snippets are in a folder named 'php' so no confusions).

Anyway isn't that going to make serious disturbances within my code ?

Upvotes: 1

Views: 261

Answers (2)

konsolenfreddy
konsolenfreddy

Reputation: 9671

If you remove the file extension from your include files and didn't setup your webserver accordingly, those includes can be viewed as regular text files as they're not interpreted by PHP (if the're within the web root)

Upvotes: 0

Abhay
Abhay

Reputation: 6645

No, you don't need to use ".php" extension for "include_once()" or "include()". You may use any extension like may be .txt or .inc. The point to note that any PHP code in the included file is enclosed in the PHP tag, otherwise it will be treated as HTML.

Another point to consider is to not keep sensitive information in the included files (mainly if you choose to give them a non-.php extension) to prevent them being accessed on the browser. Or keep those files outside your document root.

Upvotes: 2

Related Questions