Is it possible to include one php file into another php file or html file?

Submitted 3 years, 9 months ago
Ticket #370
Views 451
Language/Framework Other
Priority Medium
Status Closed

Recently I have been working on php pages...

So I am not clear whether it is possible to include php files into other files or not...

So any help will be appreciated...

Submitted on Mar 09, 21
add a comment

1 Answer

Verified

Let's say you have 2 .php files called: index.php and functions.php.

If it's mandatory that functions.php is included inside index.php, use require, or require_once

If it's not mandatory that functions.php is included inside index.php, use include of include_once.

Be sure to use relative paths.

For relative paths, use:  dirname(__DIR__).'/functions.php', with include / include_once or require/require_once

Resources:
include (https://www.php.net/manual/ro/function.include.php)
include_once (https://www.php.net/manual/ro/function.include-once.php)
require (https://www.php.net/manual/ro/function.require.php)
require_once (https://www.php.net/manual/ro/function.require-once.php)

relative_path (stackoverflow.com) (https://stackoverflow.com/questions/17407664/php-include-relative-path)

Submitted 3 years, 8 months ago


Latest Blogs