How to execute one php file inside another?

There is a folder dirthat contains the file 1.php. 1.phpfile contains mixed htmland phpcode. In general, this is the path to the dir/1.phpfile. And at the root of the site is the file index.php.

Task: when opening the index.phpfile, this file must completely copy the contents of dir/1.phpinto itself and ensure that the address bar contains the address at http://./index.phpinstead of http://./dir/1.php.

How can this be done with PHP? (Do not offer Apache link replacement, not that case.)


Answer 1, authority 100%

  1. include
  2. require
  3. include_once
  4. require_once

Index.php listing

<?php
    include "dir/1.php";
?>

Answer 2, authority 29%

index.php:

<?php
include '/dir/1.php';

Only the best answers. Only without Apache substitutions of links. 😉


Answer 3, authority 14%

The question has been answered above. I will just explain the meaning of each of the four inclusion functions:

include  -      
require  -      ,  PHP-      
include_once -   ,   "include",      
require_once -   ,   "require",      

Leave a reply

Please enter your comment!
Please enter your name here