FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Include





imagefree
Friends! while editing a lot of PHPBB and Wordpress templates and scripts, i came to know that php has a function of Including another page into the page where php script is placed. I want to use the same in my site to make my life easier. I know it is simple for PHP coder, so i request you to please help me in this regard. My site's homepage is:

Code:
<html>
<head>
<title>Site Title is here</title>
</head>
<body>
<table>
<tr>
<td class="list"><?php /*the code is to come here.*/ ?></td>
<td class="main">The content of relevent page will come here.</td>
</tr>
</table>
</body>
</html>


The PHP code mentioned above in the CODE will include a page (HTML or .PHP, whatwver you say) and that page will contain a list (<li>) with links. The same script will be used on all the pages and it will link to all the pages on my site.

I want this because it will make the editing of site easier. I will just edit the included file and add another link and then just make another page, and its done, whole site is edited.

I think you now got my point. Please help me in this regard.

Also tell me how it works.


Thanks
mathiaus
Extremely simple
Code:
<?php include('./links.html'); ?>

The page this is located on must have a .php extension. Just change links.html to include any other file Smile
imagefree
oooooh i love you.

Is it really this much simple.

I am going to try it.

Thank you again for quick response.
imagefree
mathiaus wrote:
Extremely simple
Code:
<?php include('./links.html'); ?>

The page this is located on must have a .php extension. Just change links.html to include any other file Smile


How will it work? If i Attach a CSS file with the links.html and i also put the inline styles, will they work? And what about if i have styles in the actual page. (Say i have a tag style li, and will it work for all li tags including the included page's li tags?
mathiaus
The included file becomes part of the main file. Therefore all css styles applied to the main document, also apply to your included file.
AftershockVibe
Indeed. include() is just an easy way of getting the server to do copy and paste for you!
The World is Yours
It's also very useful for menu's and columns and such. The same way you can include css files so you only have to change one file to affect the whole website, the include will do that also. You could do this:

Code:
<?php include("header.php"); ?>


in all of your pages, and copy all of your header information into a new file and name it "header.php" that way you won't have to change the header in one file and it will change on every page!!

For more information, try this link: http://www.w3schools.com/php/php_includes.asp.

Hope this helps.
Related topics
Do we support php include and/or SSI?
PHP include code problem
Help needed with images in php include files
php include path
Wonders of the include() in PHP.
php include
PHP include()
Displaying A Default Page Not Found.
Including With PHP
php variables
PHP Toturail
HTTP AUTH with PHP and mySQL
php script in php nuke - need help!
PHP Navigation
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.