Jump to content

[solved] Globally Accessible Files


damiancds
 Share

Recommended Posts

okay, what I'm asking is that a file be accessible from anywhereexplanation:I've got a main content page (index.php)index.php includes header.php and footer.phpindex.php is in directory public_html/header.php & footer.php are in public_html/resources/includes/and header.php includes menu.html and includes.html(contains all my style sheet links in one file)i have other files (faq.php) that inlcudes both header.php & footer.phpnow both faq.php and index.php both include the header and footer files from different locationi'm asking how to do this, or if it's even possible.as of now i tried having the style sheet liinks and header.php and footer.php like this (<?php require("../../../../../../public_html/resources/includes/header.php"); ?>i'll also need global links (for my menu because it will be included in many different files)i tried having it back out all the way to the root folder and then go in but it doesn't seem to worki'd appreciate any ideas you got,thanks,

Edited by damiancds
Link to comment
Share on other sites

You can define the root by using "/", for example "/resources/includes/header.php", and that will work from anywhere in the site. Note "/" refers to the document root, not the system root.

Link to comment
Share on other sites

okay, I've got a few questions for you but i just got an idea that might work.I think that using absolute links versus relative links would work.explain: absolute links (as in domain.com/folder1/folder2/page.html) versus relative links (../folder2/page.html)the only thing i don't know is if there is a speed difference let alone if its efficient, (wild guess and say it's not at all efficient and will be much slower)now, back to Synook, I understand what you're saying but the method I'm using i don't think it will workexplain:say I've got an about page (public_html/about/history.php) that includes the menu.html nav barsay I've got another about page (public_html/information/faq.php) that includes the menu.html nav bar as wellI've also got another page say (public_html/products/category1/page2.php) that also inlcudes menu.htmlif i code the menu bar's links, for example for history.php to link to faq.php the href would read ="../information/faq.php"page2.php to get to faq.php, href would read ="../../information/faq.php"if i could just get to the root folder (public_html/) then i could just code every link from that position, but I'm not quite sure howthe problem seems to be that I need it dynamic... I don't know.I'm gonna go ahead and try my "brilliant" idea about absolute links, but let me know if there is a simple and efficient way that I'm not seeing

Link to comment
Share on other sites

Well, turns out that my idea was so brilliant, it didn't work.I'm sure it works for links but it didn't work for the php require function.I'm not sure if it would have worked for linking the style sheets eitherWell, it seems I'm open for some more ideas, no matter how brilliant they arethanks,

Link to comment
Share on other sites

PHP's root is different from the root that HTML, CSS and Javascript use.I have WAMP on my computer. If I use a / to access the root in HTML, the root will be http://localhost/, however, if I use the exact same path in PHP, the root will be C:/. This is because PHP runs on the server.

Link to comment
Share on other sites

Okay, that helped Ingolme, now it appears that the .php require functions are in working orderi thought that when i used the "/" it meant current directory, not root so I just tried backing out to the actual rooteven the styles are working right nowgod, I love w3schoolsthanks for everyone's help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...