misheck Posted November 16, 2009 Share Posted November 16, 2009 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? Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/ Share on other sites More sharing options...
mattyvx Posted November 16, 2009 Share Posted November 16, 2009 you can use full url paths instead of ROOT links. Like http://www.yoursite.com/includes/header.php should work! Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-958700 Share on other sites More sharing options...
misheck Posted November 17, 2009 Author Share Posted November 17, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-958948 Share on other sites More sharing options...
trq Posted November 17, 2009 Share Posted November 17, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-958970 Share on other sites More sharing options...
FaT3oYCG Posted November 17, 2009 Share Posted November 17, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-958979 Share on other sites More sharing options...
misheck Posted November 17, 2009 Author Share Posted November 17, 2009 I tried using http://127.0.0.1/Path/to/my/includes but that also didnt work. So I am not sure about what you mean by absolute path. Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-958987 Share on other sites More sharing options...
FaT3oYCG Posted November 17, 2009 Share Posted November 17, 2009 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 Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-959229 Share on other sites More sharing options...
misheck Posted November 17, 2009 Author Share Posted November 17, 2009 Thanks thats working for the header and everything besides the footer. So I will play around with the footer for now. Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-959466 Share on other sites More sharing options...
misheck Posted November 17, 2009 Author Share Posted November 17, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181779-solved-help-with-sharing-a-header-and-footer-accross-different-folders/#findComment-959574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.