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

Submitted 6 months, 2 weeks ago
Ticket #370
Views 91
Language 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 6 months, 2 weeks ago


Wanna Post Ad?
Reach a large group of audience by posting an ad about your business here. For more details
Drop us a Message