Re: Full versus relative URLs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PJ wrote:
> Stuart wrote:
>> 2009/2/17 PJ <af.gourmet@xxxxxxxxxxxx>:
>>   
>>> Stuart wrote:
>>>     
>>>> 2009/2/17 PJ <af.gourmet@xxxxxxxxxxxx>:
>>>>
>>>>       
>>>>> Dotan Cohen wrote:
>>>>>
>>>>>         
>>>>>>>> So put it all in one place:
>>>>>>>>
>>>>>>>> <?php
>>>>>>>> include "path.inc";
>>>>>>>> print"<a href=\"$path/dir/file.php\">";
>>>>>>>> ?>
>>>>>>>>
>>>>>>>> Full URLs don't break when users save the pages to disk.
>>>>>>>>
>>>>>>>>               
>>>>>>> That would be fine if the pages weren't being crafted in Dreamweaver,
>>>>>>> where inserting links like that is a pain.
>>>>>>>
>>>>>>>
>>>>>>>             
>>>>>> For that you'd have to ask on the Dreamweaver list. I don't really
>>>>>> like those tools.
>>>>>>
>>>>>>
>>>>>>           
>>>>> I hope I'm not out of place here, but I have a problem that seems to be
>>>>> related.
>>>>> I am using some include statements for page headers with the pages in
>>>>> various directories on the site. The problem is this... if I put
>>>>> relative statements in the page (header.php) like ../images/file.jpg and
>>>>> ../file.php etc, if the page into which I include header.php is not in
>>>>> the top level directory, the links do not work and I have to copy
>>>>> header.php to header1.php and change the references to /images otherwise
>>>>> images are not displayed and links to not work in href.
>>>>>
>>>>> e.g.:
>>>>> 1.  top level file books.php
>>>>> include ("lib/db1.php");    // Connect to database
>>>>> include ("header1.php");
>>>>>
>>>>> 2. subdirectory: /authors/a.php
>>>>> include "../header.php";
>>>>>
>>>>> I thought that using referencing the top level of the directory tree
>>>>> (../) would work form anywhere within the tree?
>>>>> Am I the victim of my own misconceptions here?
>>>>> TIA to set me straight.
>>>>>
>>>>>         
>>>> Personally I always include files relative to my current location
>>>> using the following...
>>>>
>>>>     include dirname(__FILE__).'/lib/db1.php';
>>>>
>>>>       
>>> Could you clarify, please? I don't understand. And example, perhaps?
>>> my entry in books.php is
>>> <?php include "../header.php";?>
>>> NOTE: Does it matter what
>>>     
>> <?php include dirname(__FILE__)."/../header.php"; ?>
>>
>> Simple as!
>>
>> -Stuart
>>
>>   
> Ooooouuuuhhh... I think I just grasped my quandry by the tail...
> I had not thought about it before, but the problem seems to be that my
> header(s) do sometimes include links and/or other includes... so, I
> think there is no simple solution to this. I simply have to make
> different versions of such headers for different (sub)directories.
> Thanks for the clarification.
> 

Well, just from what I've read of this thread, I think you need to step
back and do a little planning on your directory/file layout.  There are
many ways to do it, and many on this list have their own good way,
however, I think that one of the simplest for a beginner is the following:

/index.php
/header.php
/footer.php
/authors/a.php

Now have your index.php include your header.php and then whatever file
is necessary based upon certain conditions, such as GET vars in the URL,
index.php?type=authors&file=a and then whatever else, footer.php, etc...

Obviously you don't want to just include whatever appears in the URL,
but do some filtering and only accept specific values maybe, then append
the result to the absolute path of the index.php.


HTH

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux