Jump to content

Top and Bottom Includes


Daney11

Recommended Posts

Hi Guys,

Im not sure wether or not this topic is supposed to go here or in PHP Help.

Anyways, my problem is that i am creating a website and i am using top.php and bottom.php and the top and bottom of my website. Top and Bottom is my website design code etc and any other file i create will have

<?
include("top.php");
?>
New File Contents
<?
include("bottom.php");
?>

Like so.

My problem is however, when i create a new folder, for example "/teams" and create files in there and add the include top and bottom.
I use ../top.php and ../bottom.php and it displays the website, but without the images.

Im not sure what to do or if there is an easier way of doing this?

Thanks in advanced.

Dane
Link to comment
Share on other sites

the php include file will take the code out of the top.php and place it in the other file (the files inside teams). Most like the image reference is relative to the top.php file, so when the file is included in another folder, it can't find the image. Try to use absolute paths

e.g. http://www.site.com/images/image1.gif instead of images/image1.gif
Link to comment
Share on other sites

Thats what i thought.

So is this possible, im sure it is....

If i created say.... website_values.php and defined the website url

define("website_url",'http://mywebsite.com');

And then included...

include("website_values.php");

In all my files from now on and then use

$website_url/images/image1.gif instead of images/image1.gif

Would that be better? Or is there a better way of doing this?

Thanks again

Dane

Link to comment
Share on other sites

  • 2 weeks later...
I have had this same problem because I also use a standard header / footer design.

My solution is in the header page(top.php) define [code]$root='http://'.$_SERVER['HTTP_HOST'].'/' ;[/code]

Then in all your images simply call the $root var e.g. <img src=<?=$root ?>path/to/image/here.jpg >

I like using $_SERVER['HTTP_HOST']  because I can design on my home machine and then upload to my production server and I don't have to change anything and everything stays absolute

You can also define $root as  [code]$root='http://www.your_site.com/';[/code]

Not the BEST way, but it works the way I want it to.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.