Jump to content

Another Php Include Question


Tino03

Recommended Posts

I'm experiencing some trouble with it.I have two files which I include in every page, namely "top.php" and "bottom.php". These files have the layout of the site stored in them, from after the <body> tag until the content area, and from after the content area to right before the </body> tag.So that means my pages look like this.

<html><head>All head stuff</head><body><?php include("top.php"); ?>CONTENT AREA<?php include("bottom.php"); ?></body></html>

That's obviously just a simplified code. The problem is, for the main page (index.php), this works fine. But when I try to set up another page, it suddenly won't work anymore, even though I use exactly the same code.Any ideas what could cause this?

Link to comment
Share on other sites

Is that other page you're trying to set up in the same folder as the main page?Are you making sure to use .php file extension instead of .html?Are you running this locally or on a host elsewhere?

Link to comment
Share on other sites

Assuming the folders are at the same level as index.php, simply construct a path:include ('folder/top.php');If index.php is itself in a folder, you could still use a relative path:include ('../folder/top.php'); # TWO DOTS MEAN 'GO UP ONE LEVEL'Or it may be easier to start at the root level and work down:include ('/folder/top.php'); # INITIAL SLASH MEANS START FROM ROOT Designers often create files that might be imported from anywhere in the directory tree. Like if you wanted ALL files for a large company to include the same footer. That's a good argument for following my third example.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...