Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14625 reviews 1734 hosting providers

Questions & Answers

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

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 votes
Apr 15, 2012 by moon_tag
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 votes
Apr 15, 2012 by dona

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