Welcome to WebmasterWorld Guest from 54.145.173.36

Forum Moderators: incrediBILL

Message Too Old, No Replies

relative links question about my PHP include?

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

5+ Year Member



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)

5+ Year Member



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)

5+ Year Member



I'll repost it over there, OK?
2:08 am on Mar 26, 2008 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

WebmasterWorld Senior Member marcia is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.