homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

relative links question about my PHP include?

 10:19 pm on Mar 25, 2008 (gmt 0)

So in my PHP include I have three links and they all look like this ../index.php I have three different folders in my site root. My problem is I can't get the links to work for all three of the folders. If I do the relative link like this index.php then it works for the other half. Do I have to do absolute links then for the php include? Thanks



 12:52 am on Mar 26, 2008 (gmt 0)

Could you explain the question more clearly please? Actually, this thread belongs in th PHP category, not the Browser Side World category.


 12:56 am on Mar 26, 2008 (gmt 0)

I'll repost it over there, OK?


 2:08 am on Mar 26, 2008 (gmt 0)

This still might be an html issue. Are each of these directories only one level deep? If so, then ../ will take you back to the domain root - and index.html would be the bare domain's index page. If some uses of the include are more than one folder deep, then you need ../../

The big question is what does "work" mean - are you trying to send the user to the domain root? If so, then it's not a good practice to use index.html - use http://www.example.com/ instead. If you're trying to send people to the home page of the same directory where the include is being used, then you don't need any ../ at all.


 2:16 am on Mar 26, 2008 (gmt 0)

For using includes on pages in /directories/ the easiest way is to put the includes into their own directory called /includes/ and call the includes for the pages like this:

<?php include("../includes/thecode.php"); ?>

Just disable the main page of /includes/ from being viewable using an Apache deny or by uploading a blank index page. That's basically for privacy and security reasons.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved