How can I include index.php file in another file?

asked Apr 15, 2012 in General by Alpha2 (880 points)
edited Apr 15, 2012 by Alpha2

I two scripts http://mysitedotcom/myscript/script1 and http://mysitedotcom/myscript/another_folder/script2/index.php
both files have their own database and admin folders

script1 has my header and footer layout.
and script2/index.php has the content.

Now I want to include the script2/index.php file into the script1 file, can this be done? And if yes then please let me know how.

2 Answers

0 like 0 dislike
answered Apr 15, 2012 by moon_tag (1,380 points)
You can use the php require or include statements. Such as:

That will go up a directory and include script1. If you don't want to mess with the relative paths you could use the document root or dirname(__FILE__) and then append the script's folder.
0 like 0 dislike
answered Apr 15, 2012 by dona (4,540 points)

In script1:add the php code

http://mysitedotcom/myscript/script1 you go up to http://mysitedotcom/myscript/ and from there you can access another_folder/script2/index.php