Jump to content

[SOLVED] help with sharing a header and footer accross different folders


misheck

Recommended Posts

I am working on my first CMS and I have designed a header and footer that I wish to share accross my website folder. I have created a main folder with this kind of set up

 

Project1 -> (Folders) images,includes,javascripts,styles,functions, admin (files) index.php, content.php

 

files in admin index.php, edit.php, delete.php, etc.

 

My problem is for the header to display its images and scripts I need to copy the images and scripts folder into the same folder as the header. Is there anything I can do either to the header so that where ever I paste

<?php include('../includes/header.php');?>

It will use one global stylesheet and images folder?

I have tried that but its producing the same results because in the header I have a link to my CSS and javascript files etc.

 

I have also tried using

example<?php include($_SERVER['DOCUMENT_ROOT'] . '/location/to/my/file/root/includes/header.php'); ?>

 

It can read the header no matter how I put it even with ../includes but the only thing is it cannot read the css files and images for the header.

you can use full url paths instead of ROOT links.

 

Like

http://www.yoursite.com/includes/header.php

 

should work!

 

That is a url not a filepath.

 

I have tried that but its producing the same results because in the header I have a link to my CSS and javascript files etc.

 

I have also tried using

example<?php include($_SERVER['DOCUMENT_ROOT'] . '/location/to/my/file/root/includes/header.php'); ?>

 

It can read the header no matter how I put it even with ../includes but the only thing is it cannot read the css files and images for the header.

 

You need also use absolute paths within your css and html.

Baisc run down:

 

using / = site root, (root-relative) for example on WAMP it is the www folder.

 

using ./ = current directory, (relative) for example calling "./style.css" would mean that it would need to be in the same directory. NOTE: you do not have to use the ./ as any path without one is taken as using the current directory i.e. "style.css"

 

using ../ = the previous or containing directory (relative), basically the same as ./ but you read the contents of the containing directory and access the files from there (more than one can be used at a time) e.g. site->root->images "../../index.php" from then images directory would link to the index.php on the site root folder e.g. www on WAMP.

 

using http://www.example.com/ = the location you specify on any accessible website (absolute), you may need to enable allow_url_include in the php ini file to use this one and usually using the site root notation is preffered unless you are accessing a file from another site and including that.

 

Thanks,

 

Craig.

this path for example might be what you want.

 

/Project1/includes/header.php

 

which will use the site root and should work for all paths, if the images dont load then take a similar approach to any images that you have linked to and change their links to

 

/Project1/images/imagename.extension

Its now working but the only problem I am having is that the header.php is being called twice so I have to headers. So what I need to do is have a new function to check if the user is logged in and if not redirect to a login page.

 

Thanks everyone for your help.

Archived

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

×
×
  • 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.