Re: [PHP] Full versus relative URLs

2009-02-18 Thread Stuart
2009/2/18 PJ :
> Paul M Foster wrote:
>> On Wed, Feb 18, 2009 at 12:05:21PM -0500, PJ wrote:
>>
>>> Stuart wrote:
 2009/2/18 PJ :

> Stuart wrote:
>
 

>>
>> 
>>

>>> What confused me here is that often, in examples, there are all sorts of
>>> references to files and there seems to be no standard as to how to refer
>>> to them in non-scripts such as these e-mails. So, I thought that
>>> dirname(_FILE_) was a general reference to a directory name and a
>>> file... :-(
>>> I don't want to defend myself here, but I cannot be expected to know all
>>> functions and look up anything that might resemble a function...
>>> I still do not understand, and that is the keyword here, I am trying to
>>> understand things - what does /../header.php mean. I know the 2 dots
>>> mean a higher directory in Unix... but I understood that ../ would mean
>>> the root directory - so what is the / before the ../header.php mean?
>>> When including scripts or pages, i find that if I am referencing to the
>>> current directory, just the filename or /filename works. If the
>>> reference is up a level, ../ works
>>>
>>> e.g. to reference root/images/ from root/authors = ../images/file.ext
>>> from root = /images/file.ext or images/file.ext
>>>
>>> I haven't needed to go to a deeper level yet.
>>
>> Let's break it down: dirname(__FILE__) . "/../header.php";
>>
>> __FILE__ is a constant that represents the filename of whatever file
>> it's in. This filename includes the directory to the file.
>>
>> dirname() parses out just the directory for the filename passed as a
>> parameter.
>>
>> The "." is, of course, the "concatenate" parameter for PHP. So we're
>> going to add on whatever comes after the directory for the file.
>>
>> "/../header.php"
>>
>> This one is a little trickier. We want a file called header.php, but
>> it's in a directory just above where you are. In Unix/Linux (and
>> therefore most internet servers), "../header.php" represents a file
>> called header.php in the directory just above where you are. Now, you'll
>> notice that what's quoted is "/../header.php", not "../header.php".
>> There's a leading slash there. Why? That's because we're going to append
>> it to a directory which has no leading slash. So if dirname(__FILE__)
>> yields "/var/www/includes", and you just add "../header.php" to it,
>> you'd get: /var/www/includes../header.php, not the file you want. The
>> file you want is: /var/www/includes/../header.php. And in this case,
>> header.php actually resides in /var/www (one directory up from
>> /var/www/includes).
>>
>> Paul
> OK, great explanation... it's what I had been hoping for ... you're a
> great "educator"
> Thanks...

I agree that Paul's explanation was good, and I apologise for not
doing a better job of explaining it, but it would have taken you 30
seconds to break apart the line I posted and echo out each element
which would have told you exactly what was happening. Teach a man to
fish...

For future reference, any token in PHP followed by a ( will be a
function name. And if the token starts with a $ it's a function name
in a variable.

> In my case though, changing from
>
> Original: include ("lib/header1.php");
> to: include dirname(_FILE_)."/lib/header1.php";
> works, but what have I gained?

You have gained the ability to not care about INI settings. Your
original requires the current directory (.) to be specified as one of
the paths in include_path. In my experience you can never be too
specific or configuration-independent whether you think you're likely
to change server or not.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread Michael A. Peters

Johnny wrote:



Hi Thodoris,

In my opinion, the best use is to include your file with relative urls, 
like :




I believe that it best.
Including the hostname use to cause a dns lookup in some browsers which 
made it slower but I don't believe that is the case anymore.


Doing the full path relative to document root though means it does not 
break when you move the page in your hierarchy.


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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread PJ
Paul M Foster wrote:
> On Wed, Feb 18, 2009 at 12:05:21PM -0500, PJ wrote:
>
>> Stuart wrote:
>>> 2009/2/18 PJ :
>>>
 Stuart wrote:

>>> 
>>>
>
> 
>
>>>
>> What confused me here is that often, in examples, there are all sorts of
>> references to files and there seems to be no standard as to how to refer
>> to them in non-scripts such as these e-mails. So, I thought that
>> dirname(_FILE_) was a general reference to a directory name and a
>> file... :-(
>> I don't want to defend myself here, but I cannot be expected to know all
>> functions and look up anything that might resemble a function...
>> I still do not understand, and that is the keyword here, I am trying to
>> understand things - what does /../header.php mean. I know the 2 dots
>> mean a higher directory in Unix... but I understood that ../ would mean
>> the root directory - so what is the / before the ../header.php mean?
>> When including scripts or pages, i find that if I am referencing to the
>> current directory, just the filename or /filename works. If the
>> reference is up a level, ../ works
>>
>> e.g. to reference root/images/ from root/authors = ../images/file.ext
>> from root = /images/file.ext or images/file.ext
>>
>> I haven't needed to go to a deeper level yet.
>
> Let's break it down: dirname(__FILE__) . "/../header.php";
>
> __FILE__ is a constant that represents the filename of whatever file
> it's in. This filename includes the directory to the file.
>
> dirname() parses out just the directory for the filename passed as a
> parameter.
>
> The "." is, of course, the "concatenate" parameter for PHP. So we're
> going to add on whatever comes after the directory for the file.
>
> "/../header.php"
>
> This one is a little trickier. We want a file called header.php, but
> it's in a directory just above where you are. In Unix/Linux (and
> therefore most internet servers), "../header.php" represents a file
> called header.php in the directory just above where you are. Now, you'll
> notice that what's quoted is "/../header.php", not "../header.php".
> There's a leading slash there. Why? That's because we're going to append
> it to a directory which has no leading slash. So if dirname(__FILE__)
> yields "/var/www/includes", and you just add "../header.php" to it,
> you'd get: /var/www/includes../header.php, not the file you want. The
> file you want is: /var/www/includes/../header.php. And in this case,
> header.php actually resides in /var/www (one directory up from
> /var/www/includes).
>
> Paul
OK, great explanation... it's what I had been hoping for ... you're a
great "educator"
Thanks...
In my case though, changing from

Original: include ("lib/header1.php");
to: include dirname(_FILE_)."/lib/header1.php";
works, but what have I gained?


-- 

Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com

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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread PJ
Bastien Koert wrote:
> On Wed, Feb 18, 2009 at 12:05 PM, PJ  wrote:
>
>> Stuart wrote:
>>> 2009/2/18 PJ :
>>>
 Stuart wrote:

>>> 
>>>
 This generates a Fatal error: Cal to undefined function dirname() 
>> 
>>> The dirname function is present in both PHP 4 and 5 and does not rely
>>> on any external libraries. Are you sure you're spelling it right?
>>>
>>> http://php.net/dirname
>>>
>>>
 I must be really dense...
 What I don't understand in the above is this - dirname refers to what
 directory? -- the directory of the file that is including? what if the
 directory is the root directory of the site?

 (_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
 this, the file which is including the file header.php?

>>> The __FILE__ (note 2 _'s either side) constant is the full path and
>>> filename to the current script. The dirname function knocks the
>>> filename off it to give you the directory the current script is in.
>>> You can then append a / and then the relative path to the script you
>>> want to include. By doing this you're ensuring that all includes are
>>> relative to the current script and are not affected by ini settings or
>>> anything else.
>>>
>>>
 and what does the . mean and then "/../header.php" --- I don't
 understand what to enter here

>>> The . is the string append operator. I tend to assume the most basic
>>> level of PHP knowledge from users of this list and I include the
>>> string append operator in that set. You might want to find a beginners
>>> tutorial for PHP and work through that to give you a solid foundation
>>> before attempting to work with multiple scripts.
>>>
>>> -Stuart
>>>
>>>
>> What confused me here is that often, in examples, there are all sorts of
>> references to files and there seems to be no standard as to how to refer
>> to them in non-scripts such as these e-mails. So, I thought that
>> dirname(_FILE_) was a general reference to a directory name and a
>> file... :-(
>> I don't want to defend myself here, but I cannot be expected to know all
>> functions and look up anything that might resemble a function...
>> I still do not understand, and that is the keyword here, I am trying to
>> understand things - what does /../header.php mean. I know the 2 dots
>> mean a higher directory in Unix... but I understood that ../ would mean
>> the root directory - so what is the / before the ../header.php mean?
>> When including scripts or pages, i find that if I am referencing to the
>> current directory, just the filename or /filename works. If the
>> reference is up a level, ../ works
>>
>> e.g. to reference root/images/ from root/authors = ../images/file.ext
>> from root = /images/file.ext or images/file.ext
>>
>> I haven't needed to go to a deeper level yet.
>>
>> --
>>
>> Phil Jourdan --- p...@ptahhotep.com
>> http://www.ptahhotep.com
>> http://www.chiccantine.com
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> ../../ means go up two directories from the current working directory that
> your file is in
Thanks, I know that it's the dirname and the _FILE_ that were not clear
but why would I want to complicate things when my original works fine
and adding dirname(_FILE_) is just extra typing.

Original: include ("lib/header1.php");
change: include dirname(_FILE_)."/lib/header1.php";
works, but what have I gained?

Maybe my application is just not sophisticated enough...


-- 

Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com

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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread Paul M Foster
On Wed, Feb 18, 2009 at 12:05:21PM -0500, PJ wrote:

> Stuart wrote:
> > 2009/2/18 PJ :
> >
> >> Stuart wrote:
> >>
> > 
> >



> >
> >
> What confused me here is that often, in examples, there are all sorts of
> references to files and there seems to be no standard as to how to refer
> to them in non-scripts such as these e-mails. So, I thought that
> dirname(_FILE_) was a general reference to a directory name and a
> file... :-(
> I don't want to defend myself here, but I cannot be expected to know all
> functions and look up anything that might resemble a function...
> I still do not understand, and that is the keyword here, I am trying to
> understand things - what does /../header.php mean. I know the 2 dots
> mean a higher directory in Unix... but I understood that ../ would mean
> the root directory - so what is the / before the ../header.php mean?
> When including scripts or pages, i find that if I am referencing to the
> current directory, just the filename or /filename works. If the
> reference is up a level, ../ works
> 
> e.g. to reference root/images/ from root/authors = ../images/file.ext
> from root = /images/file.ext or images/file.ext
> 
> I haven't needed to go to a deeper level yet.

Let's break it down: dirname(__FILE__) . "/../header.php";

__FILE__ is a constant that represents the filename of whatever file
it's in. This filename includes the directory to the file.

dirname() parses out just the directory for the filename passed as a
parameter.

The "." is, of course, the "concatenate" parameter for PHP. So we're
going to add on whatever comes after the directory for the file.

"/../header.php"

This one is a little trickier. We want a file called header.php, but
it's in a directory just above where you are. In Unix/Linux (and
therefore most internet servers), "../header.php" represents a file
called header.php in the directory just above where you are. Now, you'll
notice that what's quoted is "/../header.php", not "../header.php".
There's a leading slash there. Why? That's because we're going to append
it to a directory which has no leading slash. So if dirname(__FILE__)
yields "/var/www/includes", and you just add "../header.php" to it,
you'd get: /var/www/includes../header.php, not the file you want. The
file you want is: /var/www/includes/../header.php. And in this case,
header.php actually resides in /var/www (one directory up from
/var/www/includes).

Paul
-- 
Paul M. Foster

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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread 9el
---
Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get
a Free CD of Ubuntu mailed to your door without any cost. Visit :
www.ubuntu.com
--


On Wed, Feb 18, 2009 at 11:05 PM, PJ  wrote:

> Stuart wrote:
> > 2009/2/18 PJ :
> >
> >> Stuart wrote:
> >>
> > 
> >
> >> This generates a Fatal error: Cal to undefined function dirname() 
> 
> >>
> >
> > The dirname function is present in both PHP 4 and 5 and does not rely
> > on any external libraries. Are you sure you're spelling it right?
> >
> > http://php.net/dirname
>

dirname
(PHP 4, PHP 5)
dirname — Returns directory name component of path
Description
string dirname ( string $path )
Given a string containing a path to a file, this function will return the
name of the directory.
Parameters
path
A path.
On Windows, both slash (/) and backslash (\) are used as directory separator
character. In other environments, it is the forward slash (/).
Return Values
Returns the name of the directory. If there are no slashes in path , a dot
('.') is returned, indicating the current directory. Otherwise, the returned
string is path with any trailing /component removed.
Changelog
Version
Description
5.0.0
dirname() is now binary safe
4.0.3
dirname() was fixed to be POSIX-compliant.
Examples
Example #1 dirname() example

Notes
Note: Since PHP 4.3.0, you will often get a slash or a dot back from
dirname() in situations where the older functionality would have given you
the empty string.
Check the following change example:


>
> >
> >
> >> I must be really dense...
> >> What I don't understand in the above is this - dirname refers to what
> >> directory? -- the directory of the file that is including? what if the
> >> directory is the root directory of the site?
> >>
> >> (_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
> >> this, the file which is including the file header.php?
> >>
> >
> > The __FILE__ (note 2 _'s either side) constant is the full path and
> > filename to the current script. The dirname function knocks the
> > filename off it to give you the directory the current script is in.
> > You can then append a / and then the relative path to the script you
> > want to include. By doing this you're ensuring that all includes are
> > relative to the current script and are not affected by ini settings or
> > anything else.
> >
> >
> >> and what does the . mean and then "/../header.php" --- I don't
> >> understand what to enter here
>
the . before the quotemark  is the concatenation operator which joins the
string(texts) together. :)



> >>
> >
> > The . is the string append operator. I tend to assume the most basic
> > level of PHP knowledge from users of this list and I include the
> > string append operator in that set. You might want to find a beginners
> > tutorial for PHP and work through that to give you a solid foundation
> > before attempting to work with multiple scripts.
> >
> > -Stuart
> >
> >
> What confused me here is that often, in examples, there are all sorts of
> references to files and there seems to be no standard as to how to refer
> to them in non-scripts such as these e-mails. So, I thought that
> dirname(_FILE_) was a general reference to a directory name and a
> file... :-(
> I don't want to defend myself here, but I cannot be expected to know all
> functions and look up anything that might resemble a function...
> I still do not understand, and that is the keyword here, I am trying to
> understand things - what does /../header.php mean. I know the 2 dots
> mean a higher directory in Unix... but I understood that ../ would mean
> the root directory - so what is the / before the ../header.php mean?
> When including scripts or pages, i find that if I am referencing to the
> current directory, just the filename or /filename works. If the
> reference is up a level, ../ works
>
> e.g. to reference root/images/ from root/authors = ../images/file.ext
> from root = /images/file.ext or images/file.ext
>
> I haven't needed to go to a deeper level yet.
>
> --
>
> Phil Jourdan --- p...@ptahhotep.com
>   http://www.ptahhotep.com
>   http://www.chiccantine.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Full versus relative URLs

2009-02-18 Thread Bastien Koert
On Wed, Feb 18, 2009 at 12:05 PM, PJ  wrote:

> Stuart wrote:
> > 2009/2/18 PJ :
> >
> >> Stuart wrote:
> >>
> > 
> >
> >> This generates a Fatal error: Cal to undefined function dirname() 
> 
> >>
> >
> > The dirname function is present in both PHP 4 and 5 and does not rely
> > on any external libraries. Are you sure you're spelling it right?
> >
> > http://php.net/dirname
> >
> >
> >> I must be really dense...
> >> What I don't understand in the above is this - dirname refers to what
> >> directory? -- the directory of the file that is including? what if the
> >> directory is the root directory of the site?
> >>
> >> (_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
> >> this, the file which is including the file header.php?
> >>
> >
> > The __FILE__ (note 2 _'s either side) constant is the full path and
> > filename to the current script. The dirname function knocks the
> > filename off it to give you the directory the current script is in.
> > You can then append a / and then the relative path to the script you
> > want to include. By doing this you're ensuring that all includes are
> > relative to the current script and are not affected by ini settings or
> > anything else.
> >
> >
> >> and what does the . mean and then "/../header.php" --- I don't
> >> understand what to enter here
> >>
> >
> > The . is the string append operator. I tend to assume the most basic
> > level of PHP knowledge from users of this list and I include the
> > string append operator in that set. You might want to find a beginners
> > tutorial for PHP and work through that to give you a solid foundation
> > before attempting to work with multiple scripts.
> >
> > -Stuart
> >
> >
> What confused me here is that often, in examples, there are all sorts of
> references to files and there seems to be no standard as to how to refer
> to them in non-scripts such as these e-mails. So, I thought that
> dirname(_FILE_) was a general reference to a directory name and a
> file... :-(
> I don't want to defend myself here, but I cannot be expected to know all
> functions and look up anything that might resemble a function...
> I still do not understand, and that is the keyword here, I am trying to
> understand things - what does /../header.php mean. I know the 2 dots
> mean a higher directory in Unix... but I understood that ../ would mean
> the root directory - so what is the / before the ../header.php mean?
> When including scripts or pages, i find that if I am referencing to the
> current directory, just the filename or /filename works. If the
> reference is up a level, ../ works
>
> e.g. to reference root/images/ from root/authors = ../images/file.ext
> from root = /images/file.ext or images/file.ext
>
> I haven't needed to go to a deeper level yet.
>
> --
>
> Phil Jourdan --- p...@ptahhotep.com
>   http://www.ptahhotep.com
>   http://www.chiccantine.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

../../ means go up two directories from the current working directory that
your file is in
-- 

Bastien

Cat, the other other white meat


Re: [PHP] Full versus relative URLs

2009-02-18 Thread PJ
Stuart wrote:
> 2009/2/18 PJ :
>   
>> Stuart wrote:
>> 
> 
>   
>> This generates a Fatal error: Cal to undefined function dirname()  
>> 
>
> The dirname function is present in both PHP 4 and 5 and does not rely
> on any external libraries. Are you sure you're spelling it right?
>
> http://php.net/dirname
>
>   
>> I must be really dense...
>> What I don't understand in the above is this - dirname refers to what
>> directory? -- the directory of the file that is including? what if the
>> directory is the root directory of the site?
>>
>> (_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
>> this, the file which is including the file header.php?
>> 
>
> The __FILE__ (note 2 _'s either side) constant is the full path and
> filename to the current script. The dirname function knocks the
> filename off it to give you the directory the current script is in.
> You can then append a / and then the relative path to the script you
> want to include. By doing this you're ensuring that all includes are
> relative to the current script and are not affected by ini settings or
> anything else.
>
>   
>> and what does the . mean and then "/../header.php" --- I don't
>> understand what to enter here
>> 
>
> The . is the string append operator. I tend to assume the most basic
> level of PHP knowledge from users of this list and I include the
> string append operator in that set. You might want to find a beginners
> tutorial for PHP and work through that to give you a solid foundation
> before attempting to work with multiple scripts.
>
> -Stuart
>
>   
What confused me here is that often, in examples, there are all sorts of
references to files and there seems to be no standard as to how to refer
to them in non-scripts such as these e-mails. So, I thought that
dirname(_FILE_) was a general reference to a directory name and a
file... :-(
I don't want to defend myself here, but I cannot be expected to know all
functions and look up anything that might resemble a function...
I still do not understand, and that is the keyword here, I am trying to
understand things - what does /../header.php mean. I know the 2 dots
mean a higher directory in Unix... but I understood that ../ would mean
the root directory - so what is the / before the ../header.php mean?
When including scripts or pages, i find that if I am referencing to the
current directory, just the filename or /filename works. If the
reference is up a level, ../ works

e.g. to reference root/images/ from root/authors = ../images/file.ext
from root = /images/file.ext or images/file.ext

I haven't needed to go to a deeper level yet.

-- 

Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com


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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread Shawn McKenzie
PJ wrote:
> Stuart wrote:
>> 2009/2/17 PJ :
>>   
>>> Stuart wrote:
>>> 
 2009/2/17 PJ :

   
> Dotan Cohen wrote:
>
> 
 So put it all in one place:

 >>> include "path.inc";
 print"";
 ?>

 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
>>> 
>>> NOTE: Does it matter what
>>> 
>> 
>>
>> Simple as!
>>
>> -Stuart
>>
>>   
> Ohhh... 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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread Johnny

Thodoris a écrit :



Here's a question related to my last post. When specifying a link in a
HTML file (like to the css or an image file), there are two ways of
doing it. One is to simply include the relative path to the file
(relative to the doc root), like:

/graphics/my_portrait.gif

Or you can include the full URL, like:

http://example.com/graphics/my_portrait.gif

My casual observation seems to indicate that the former will load faster
than the latter. But has anyone done any benchmarking on it?

Paul

  


I am not aware if absolute URLs are faster or not (in case they are 
there will be such a small difference you cannot probably notice) but  
IMHO it is a bad practice to use full URLs.


Basically because renaming directories or scripts will cause great pain 
in the ass.


Of course resources that are coming outside your own site are needed to 
use absolute URLs and nobody is assuming that are useless.




Hi Thodoris,

In my opinion, the best use is to include your file with relative urls, 
like :


for "client side files" (file from browsers.

For includes serverside, i usually use $_SERVER['DOCUMENT_ROOT'] "root 
path" for inclusion, like :


require_once($_SERVER['DOCUMENT_ROOT'] . '/../init/init.base.inc');

regards,

Joko

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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread 9el
---
Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get
a Free CD of Ubuntu mailed to your door without any cost. Visit :
www.ubuntu.com
--


On Wed, Feb 18, 2009 at 8:02 PM, Stuart  wrote:

> 2009/2/18 PJ :
> > Stuart wrote:
>  
> > This generates a Fatal error: Cal to undefined function dirname() 
> 
>
> The dirname function is present in both PHP 4 and 5 and does not rely
> on any external libraries. Are you sure you're spelling it right?
>
> http://php.net/dirname
>
> > I must be really dense...
> > What I don't understand in the above is this - dirname refers to what
> > directory? -- the directory of the file that is including? what if the
> > directory is the root directory of the site?
> >
> > (_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
> > this, the file which is including the file header.php?
>
> The __FILE__ (note 2 _'s either side) constant is the full path and
> filename to the current script. The dirname function knocks the
> filename off it to give you the directory the current script is in.
> You can then append a / and then the relative path to the script you
> want to include. By doing this you're ensuring that all includes are
> relative to the current script and are not affected by ini settings or
> anything else.
>
> > and what does the . mean and then "/../header.php" --- I don't
> > understand what to enter here
>

. (dot)  is string concatenator/concatenation operator. And  .. (double dot)
used in a path is a shorthand for parent directory.  Goto your command
console . ie.  CMD or Command.com or linux console type  cd .. and press
enter it will take you to one level up.  also in this shorthand . (a single
dot) means current directory/folder (please dont mixup with concatenation
operator)

>
>
> The . is the string append operator. I tend to assume the most basic
> level of PHP knowledge from users of this list and I include the
> string append operator in that set. You might want to find a beginners
> tutorial for PHP and work through that to give you a solid foundation
> before attempting to work with multiple scripts.
>
> -Stuart
>
> --
> http://stut.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Full versus relative URLs

2009-02-18 Thread Stuart
2009/2/18 PJ :
> Stuart wrote:
 
> This generates a Fatal error: Cal to undefined function dirname()  

The dirname function is present in both PHP 4 and 5 and does not rely
on any external libraries. Are you sure you're spelling it right?

http://php.net/dirname

> I must be really dense...
> What I don't understand in the above is this - dirname refers to what
> directory? -- the directory of the file that is including? what if the
> directory is the root directory of the site?
>
> (_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
> this, the file which is including the file header.php?

The __FILE__ (note 2 _'s either side) constant is the full path and
filename to the current script. The dirname function knocks the
filename off it to give you the directory the current script is in.
You can then append a / and then the relative path to the script you
want to include. By doing this you're ensuring that all includes are
relative to the current script and are not affected by ini settings or
anything else.

> and what does the . mean and then "/../header.php" --- I don't
> understand what to enter here

The . is the string append operator. I tend to assume the most basic
level of PHP knowledge from users of this list and I include the
string append operator in that set. You might want to find a beginners
tutorial for PHP and work through that to give you a solid foundation
before attempting to work with multiple scripts.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread PJ
Stuart wrote:
>>> 
This generates a Fatal error: Cal to undefined function dirname()  

I must be really dense...
What I don't understand in the above is this - dirname refers to what
directory? -- the directory of the file that is including? what if the
directory is the root directory of the site?

(_FILE_) = what? - (_filename.ext_) or (filename.ext) --- what file is
this, the file which is including the file header.php?

and what does the . mean and then "/../header.php" --- I don't
understand what to enter here

>>> Simple as!
>>>
>>> -Stuart
>>>
>>>
>>>   
>> Ohhh... 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.
>> 
>
> I said what now?
>
> By using dirname it doesn't matter where a file is included from so
> long as it's never moved to a different relative location to the stuff
> it includes.
>
> But if you've had some sudden enlightenment I wish you luck with it.
>
> -Stuart
>
>   


-- 

Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com


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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread PJ
Stuart wrote:
> 2009/2/17 PJ :
>   
>> Stuart wrote:
>> 
>>> 2009/2/17 PJ :
>>>
>>>   
 Dotan Cohen wrote:

 
>>> So put it all in one place:
>>>
>>> >> include "path.inc";
>>> print"";
>>> ?>
>>>
>>> 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
>> 
>> NOTE: Does it matter what
>> 
>
> 
>
> Simple as!
>
> -Stuart
>
>   
Ohhh... 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.

-- 

Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com


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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread Stuart
2009/2/18 PJ :
> Stuart wrote:
>> 2009/2/17 PJ :
>>
>>> Stuart wrote:
>>>
 2009/2/17 PJ :


> Dotan Cohen wrote:
>
>
 So put it all in one place:

 >>> include "path.inc";
 print"";
 ?>

 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
>>> 
>>> NOTE: Does it matter what
>>>
>>
>> 
>>
>> Simple as!
>>
>> -Stuart
>>
>>
> Ohhh... 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.

I said what now?

By using dirname it doesn't matter where a file is included from so
long as it's never moved to a different relative location to the stuff
it includes.

But if you've had some sudden enlightenment I wish you luck with it.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Full versus relative URLs

2009-02-18 Thread Stuart
2009/2/17 PJ :
> Stuart wrote:
>> 2009/2/17 PJ :
>>
>>> Dotan Cohen wrote:
>>>
>> So put it all in one place:
>>
>> > include "path.inc";
>> print"";
>> ?>
>>
>> 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
> 
> NOTE: Does it matter what



Simple as!

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Michael A. Peters

PJ wrote:


my server is FreeBSD 7.0

My situation is this: I am evolving www.ptahhotep.com from pure HTML to
php-mysql-css (not an easy task for a newbie :-) )
The challenge is to set up the web site on my local server and then move
it all to my web host.
Unless I am mistaken, I am pretty sure I have no access to the setup
files for apache, mysql or anything else. So, I don't think I can use
the ini_set() function.


I suspect it will still work - I use xen based hosting now so I have 
complete control, but ini_set worked when I used shared hosting, at 
least for setting the php include directory.


Good luck with your project.

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread PJ
Stuart wrote:
> 2009/2/17 PJ :
>   
>> Dotan Cohen wrote:
>> 
> So put it all in one place:
>
>  include "path.inc";
> print"";
> ?>
>
> 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

NOTE: Does it matter what
> That way it doesn't matter how INI vars are set up and I don't need to
> fanny around with setting them at runtime.
>
> -Stuart
- 

Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com


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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread PJ
Michael A. Peters wrote:
> PJ wrote:
>> Michael A. Peters wrote:
>>> PJ wrote:
>>>
 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.
>>> Easy to solve.
>> I neglected to mention, although, it must be fairly obvious that I'm
>> fairly new to all this ["newbie" but not virgin :-) ]
>> Comments below -->
>>> ini_set("include_path",
>>> "/srv/domain/phpinclude:/srv/domain/record_include:/srv/domain/process_include");
>>>
>>>
>> 1. Where to I put it?
>> 2. srv = ? domain = ? phpinclude = ? record, process... = ? server, but
>> like what? a url?
>
> /srv/domain/phpinclude is just an example directory path.
>
> /var/www or /usr/www are other common examples.
>
> If your server is Windows, I don't have any experience with how php
> sees windows file paths, but I believe it still uses a unix like
> forward slash syntax.
my server is FreeBSD 7.0

My situation is this: I am evolving www.ptahhotep.com from pure HTML to
php-mysql-css (not an easy task for a newbie :-) )
The challenge is to set up the web site on my local server and then move
it all to my web host.
Unless I am mistaken, I am pretty sure I have no access to the setup
files for apache, mysql or anything else. So, I don't think I can use
the ini_set() function.
Therefore, I am limited to the document root & subdirectories.
So, I still don't understand how the include statement should be
formulated so that when I include a file it will be included from
anywhere in the direcctory tree.
>
>>> Then just call it without path - IE
>>>
>>> include('foo.inc');
>>>
>>> php will first look for foo.inc in /srv/domain/phpinclude, then in
>>> /srv/domain/record_include, etc.
>>>
>>> make directories for your includes, preferably outside the web root,
>>> and define your include path at the top of your script.
>>>
>>> I personally don't like to have . as part of my include path, and
>>> relative include paths (id somedir/foo.inc) are IMHO an even worse
>>> practice.
>> What do you suggest as a better prctice?
>
> I make application specific directories for include files, and put all
> include files into that application specific directory (application
> mean web application). Sometimes I have more than one if it is a big
> web application.
>
> Doing it that way allows me to include the same files with several
> webapps on the same server, lets me move the php files around etc.
> without needing to worry about moving the include files, because the
> directory where they are served from is part of the include path.
>
> It makes upgrading web apps a lot easier - often times you can leave
> the individual php files alone, it's the include files that get
> updated. So when you are developing a new improved version of your web
> app, you can just upload the new directory to your production server
> and change one line in the actual php file (where you define the
> include_path) and your web app is updated - making it cake to roll
> back a week later if you find you need to.
>
> Separate the pages that are actually served from the pages that are
> included. It makes a lot of things easier down the road.
>
>>
>
>


-- 

Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com


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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Michael A. Peters

PJ wrote:

Michael A. Peters wrote:

PJ wrote:


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.

Easy to solve.

I neglected to mention, although, it must be fairly obvious that I'm
fairly new to all this ["newbie" but not virgin :-) ]
Comments below -->

ini_set("include_path",
"/srv/domain/phpinclude:/srv/domain/record_include:/srv/domain/process_include");


1. Where to I put it?
2. srv = ? domain = ? phpinclude = ? record, process... = ? server, but
like what? a url?


/srv/domain/phpinclude is just an example directory path.

/var/www or /usr/www are other common examples.

If your server is Windows, I don't have any experience with how php sees 
windows file paths, but I believe it still uses a unix like forward 
slash syntax.



Then just call it without path - IE

include('foo.inc');

php will first look for foo.inc in /srv/domain/phpinclude, then in
/srv/domain/record_include, etc.

make directories for your includes, preferably outside the web root,
and define your include path at the top of your script.

I personally don't like to have . as part of my include path, and
relative include paths (id somedir/foo.inc) are IMHO an even worse
practice.

What do you suggest as a better prctice?


I make application specific directories for include files, and put all 
include files into that application specific directory (application mean 
web application). Sometimes I have more than one if it is a big web 
application.


Doing it that way allows me to include the same files with several 
webapps on the same server, lets me move the php files around etc. 
without needing to worry about moving the include files, because the 
directory where they are served from is part of the include path.


It makes upgrading web apps a lot easier - often times you can leave the 
individual php files alone, it's the include files that get updated. So 
when you are developing a new improved version of your web app, you can 
just upload the new directory to your production server and change one 
line in the actual php file (where you define the include_path) and your 
web app is updated - making it cake to roll back a week later if you 
find you need to.


Separate the pages that are actually served from the pages that are 
included. It makes a lot of things easier down the road.







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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread PJ
Michael A. Peters wrote:
> PJ wrote:
>
>>>
>> 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.
> Easy to solve.
I neglected to mention, although, it must be fairly obvious that I'm
fairly new to all this ["newbie" but not virgin :-) ]
Comments below -->
> ini_set("include_path",
> "/srv/domain/phpinclude:/srv/domain/record_include:/srv/domain/process_include");
>
1. Where to I put it?
2. srv = ? domain = ? phpinclude = ? record, process... = ? server, but
like what? a url?
>
> Then just call it without path - IE
>
> include('foo.inc');
>
> php will first look for foo.inc in /srv/domain/phpinclude, then in
> /srv/domain/record_include, etc.
>
> make directories for your includes, preferably outside the web root,
> and define your include path at the top of your script.
>
> I personally don't like to have . as part of my include path, and
> relative include paths (id somedir/foo.inc) are IMHO an even worse
> practice.
What do you suggest as a better prctice?

-- 

Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com


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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Stuart
2009/2/17 PJ :
> Dotan Cohen wrote:
 So put it all in one place:

 >>> include "path.inc";
 print"";
 ?>

 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';

That way it doesn't matter how INI vars are set up and I don't need to
fanny around with setting them at runtime.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Dotan Cohen
> Easy to solve.
>
> ini_set("include_path",
> "/srv/domain/phpinclude:/srv/domain/record_include:/srv/domain/process_include");
>
> Then just call it without path - IE
>
> include('foo.inc');
>
> php will first look for foo.inc in /srv/domain/phpinclude, then in
> /srv/domain/record_include, etc.
>
> make directories for your includes, preferably outside the web root, and
> define your include path at the top of your script.
>
> I personally don't like to have . as part of my include path, and relative
> include paths (id somedir/foo.inc) are IMHO an even worse practice.
>

I did not know that his was possible. Thanks!

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü


Re: [PHP] Full versus relative URLs

2009-02-17 Thread Dotan Cohen
> > Alternatively, $_SERVER['PHP_SELF']) could be switch()ed for known
> > values, and $path be set accordingly with hardcoded values.
>> Didn't notice this thread passing from the list. I will look into it.
>
> But sometimes you need to detect where something is located and that's the
> point of the whole conversation. If you hardcode the values then you need to
> change them while renaming or moving files and directories
>
> So what someone should do to accomplish such a behavior? Without being
> vulnerable to injection attacks of course.
>

It's not vulnerable to injection in the sense that the attacker could
not redirect the links to his site. At a maximum he could disable the
links, but he could not redirect them. That's why I mean by hardcoded.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü


Re: [PHP] Full versus relative URLs

2009-02-17 Thread Michael A. Peters

PJ wrote:




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.


Easy to solve.

ini_set("include_path", 
"/srv/domain/phpinclude:/srv/domain/record_include:/srv/domain/process_include");


Then just call it without path - IE

include('foo.inc');

php will first look for foo.inc in /srv/domain/phpinclude, then in 
/srv/domain/record_include, etc.


make directories for your includes, preferably outside the web root, and 
define your include path at the top of your script.


I personally don't like to have . as part of my include path, and 
relative include paths (id somedir/foo.inc) are IMHO an even worse practice.


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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread PJ
Dotan Cohen wrote:
>>> So put it all in one place:
>>>
>>> >> include "path.inc";
>>> print"";
>>> ?>
>>>
>>> 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.
-- 

Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Thodoris





for that matter, you could use variables to specify the relative path to make 
it absolute within each of the production and dev environments.

  


Another possible solution I can think is building configuration files 
that could include the paths and parse them to find the path every time 
you need it. This conf files would be different between the two machines 
and you will only need to upload the source files without consideration 
since the directories will actually inside the conf files.


A database table that would store the paths could always be an 
alternative that you could perhaps load into the session to avoid overhead.


--
Thodoris



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Thodoris



I know it's been said before, but beware of relying on this value just
for the sole purpose of deciding where things are located, as without a
bit of error checking on it, it can be used for injection attacks and
what-not, although, sadly, I forget the exact post recently that had the
link that explained this issue on PHP_SELF.




Alternatively, $_SERVER['PHP_SELF']) could be switch()ed for known
values, and $path be set accordingly with hardcoded values.

  

Didn't notice this thread passing from the list. I will look into it.

But sometimes you need to detect where something is located and that's 
the point of the whole conversation. If you hardcode the values then you 
need to change them while renaming or moving files and directories


So what someone should do to accomplish such a behavior? Without being 
vulnerable to injection attacks of course.


--
Thodoris



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Jim Lucas
Lewis Wright wrote:
> But that's where mistakes are often made. It also means you need to
> maintain a different live version to that of your development version.
> If find it much easier to have relative paths and then there's no
> build process needed to go live, I can just upload it.
> 
> 2009/2/17 Michael A. Peters :
>> Virgilio Quilario wrote:
>>
>>> The difference is in manageability.
>>> Copying the scripts to another domain and you're using full url for
>>> your src and href when referring to local images or css or pages, will
>>> give you trouble and you must change all of them to your new domain.
>> which takes about 3 seconds to do with sed.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> 

for that matter, you could use variables to specify the relative path to make 
it absolute within each of the production and dev environments.

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Lewis Wright
But that's where mistakes are often made. It also means you need to
maintain a different live version to that of your development version.
If find it much easier to have relative paths and then there's no
build process needed to go live, I can just upload it.

2009/2/17 Michael A. Peters :
> Virgilio Quilario wrote:
>
>> The difference is in manageability.
>> Copying the scripts to another domain and you're using full url for
>> your src and href when referring to local images or css or pages, will
>> give you trouble and you must change all of them to your new domain.
>
> which takes about 3 seconds to do with sed.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Michael A. Peters

Virgilio Quilario wrote:

> The difference is in manageability.
> Copying the scripts to another domain and you're using full url for
> your src and href when referring to local images or css or pages, will
> give you trouble and you must change all of them to your new domain.

which takes about 3 seconds to do with sed.

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Paul M Foster
On Tue, Feb 17, 2009 at 11:22:32AM +, Stuart wrote:

> 2009/2/17 Paul M Foster :



> 
> Maintaining identical development, staging and live environments is
> one of the key components of reliable, repeatable and streamlined
> development, testing and deployment, but if you're happy with what
> you've got then by all means continue as before. I was just offering a
> best practice suggestion that would solve your current problem and
> likely some you'll encounter in the future.

All agreed. That is the safest alternative. Will I do it that way? Not
so much. Yes, I know I reap the consequences.



> 
> Most DHCP servers can reserve an IP address for a specific MAC address
> such that that IP always gets given to that NIC.

Actually, that's what happens in this case. But I could change that IP
one day and forget to hack the hosts file. I prefer to treat it as
non-fixed.



> 
> > Really, Stuart, you should try not to be so annoyed at people who don't
> > appear to know as much as you believe you do. ;-}
> 
> I'm not annoyed, I'm mildly frustrated. You did not respond to my
> initial suggestion in the other thread but continued to discuss the
> problem with others. I apologise if my tone came across as annoyed,
> but it's polite to respond to others when they communicate with you.

All this because I didn't answer you on another thread? Wow. I typically
don't reply to suggestions whose nature I'm already aware of as an
alternative. Sorry about that.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Virgilio Quilario
> Here's a question related to my last post. When specifying a link in a
> HTML file (like to the css or an image file), there are two ways of
> doing it. One is to simply include the relative path to the file
> (relative to the doc root), like:
>
> /graphics/my_portrait.gif
>
> Or you can include the full URL, like:
>
> http://example.com/graphics/my_portrait.gif
>
> My casual observation seems to indicate that the former will load faster
> than the latter. But has anyone done any benchmarking on it?
>

Hi Paul,

There is no difference in speed.
The difference is in manageability.
Copying the scripts to another domain and you're using full url for
your src and href when referring to local images or css or pages, will
give you trouble and you must change all of them to your new domain.

Virgil
http://www.jampmark.com

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



Re: [PHP] Full versus relative URLs

2009-02-17 Thread Stuart
2009/2/17 Paul M Foster :
> On Mon, Feb 16, 2009 at 08:49:06PM +, Stuart wrote:
>
>> 2009/2/16 Paul M Foster :
>
> 
>
>> >
>> > Agreed. But here's the real reason, in my case. We develop the pages on
>> > an internal server, which has the URL http://pokey/mysite.com. When we
>> > move the pages to the live server at mysite.com, all the URLs would have
>> > to be rewritten. Ugh.
>>
>> My advice would be to stop coding and sort this out as soon as
>> possible.
>
> You think? ;-}
>
>> If your development server has a different layout to your
>> live server you're simply asking for trouble, especially since you're
>> using a front controller pattern (as evidenced in another thread).
>
> Not so much. We've structured our backups and live servers this way for
> a number of years without incident. Paqes for clients are normally
> statically built in Dreamweaver, with possibly a modicum of PHP to
> handle forms. Internal company pages are built by me and reside only on
> internal servers. This is the first client project where we're using a
> front controller, etc.

Not encountering a problem for "a number of years" does not mean
you're not going to have problems in the future. I know a lot of
people who don't backup their data, some who justify it by asserting
that they've not had a problem so far.

Maintaining identical development, staging and live environments is
one of the key components of reliable, repeatable and streamlined
development, testing and deployment, but if you're happy with what
you've got then by all means continue as before. I was just offering a
best practice suggestion that would solve your current problem and
likely some you'll encounter in the future.

>> It's simple to fix this. Add a hosts entry for mysite.local pointing
>> at pokey's IP. Change the server software so it has a virtual host for
>> mysite.local pointed at the mysite.com directory in the existing web
>> rooot.
>
> Which works up until the point where you go live with the site, and
> forget to revert the hosts file, so you can't get to the live site. And
> after you do revert the hosts file, you again have the same problem with
> the base URL for the production site being different from the
> development/backup site.
>
> Virtual hosting is beyond my Apache expertise, and again, would mask
> live sites we host.

No it wouldn't. If you care to read exactly what I wrote, you put the
development site under mysite.local rather than mysite.com. It won't
mask or hide the live site and it won't have any negative impact when
you put it live unless you've used the domain name in links.

> In addition, pokey's IP is not exactly fixed. It's served up by DHCP
> from an internal DHCP server. It's generally the same, but I wouldn't
> want to rely on that in a hosts file.

Most DHCP servers can reserve an IP address for a specific MAC address
such that that IP always gets given to that NIC.

>> This is not difficult and will allow you to solve both of the problems
>> you are currently asking this list about.
>
> Actually, Ashley's  tag solution resolves the problem. However,
> I've moved on and dropped the front controller concept for this project.
> Instead, I'm opting for a snippet of PHP at the beginning of every
> "static" page built in DW which calls in the values necessary to
> populate the sidebars of the pages.

That's completely up to you, I'm just trying to help.

> Really, Stuart, you should try not to be so annoyed at people who don't
> appear to know as much as you believe you do. ;-}

I'm not annoyed, I'm mildly frustrated. You did not respond to my
initial suggestion in the other thread but continued to discuss the
problem with others. I apologise if my tone came across as annoyed,
but it's polite to respond to others when they communicate with you.

Good day to you sir ;-)

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Full versus relative URLs

2009-02-16 Thread Paul M Foster
On Mon, Feb 16, 2009 at 08:49:06PM +, Stuart wrote:

> 2009/2/16 Paul M Foster :



> >
> > Agreed. But here's the real reason, in my case. We develop the pages on
> > an internal server, which has the URL http://pokey/mysite.com. When we
> > move the pages to the live server at mysite.com, all the URLs would have
> > to be rewritten. Ugh.
> 
> My advice would be to stop coding and sort this out as soon as
> possible. 

You think? ;-}

> If your development server has a different layout to your
> live server you're simply asking for trouble, especially since you're
> using a front controller pattern (as evidenced in another thread).

Not so much. We've structured our backups and live servers this way for
a number of years without incident. Paqes for clients are normally
statically built in Dreamweaver, with possibly a modicum of PHP to
handle forms. Internal company pages are built by me and reside only on
internal servers. This is the first client project where we're using a
front controller, etc.

> 
> It's simple to fix this. Add a hosts entry for mysite.local pointing
> at pokey's IP. Change the server software so it has a virtual host for
> mysite.local pointed at the mysite.com directory in the existing web
> rooot.

Which works up until the point where you go live with the site, and
forget to revert the hosts file, so you can't get to the live site. And
after you do revert the hosts file, you again have the same problem with
the base URL for the production site being different from the
development/backup site.

Virtual hosting is beyond my Apache expertise, and again, would mask
live sites we host.

In addition, pokey's IP is not exactly fixed. It's served up by DHCP
from an internal DHCP server. It's generally the same, but I wouldn't
want to rely on that in a hosts file.

> 
> This is not difficult and will allow you to solve both of the problems
> you are currently asking this list about.

Actually, Ashley's  tag solution resolves the problem. However,
I've moved on and dropped the front controller concept for this project.
Instead, I'm opting for a snippet of PHP at the beginning of every
"static" page built in DW which calls in the values necessary to
populate the sidebars of the pages.

Really, Stuart, you should try not to be so annoyed at people who don't
appear to know as much as you believe you do. ;-}

Paul

-- 
Paul M. Foster

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



Re: [PHP] Full versus relative URLs

2009-02-16 Thread Stuart
2009/2/16 Paul M Foster :
> On Mon, Feb 16, 2009 at 07:39:29PM +0200, Thodoris wrote:
>
>>
>>> Here's a question related to my last post. When specifying a link in a
>>> HTML file (like to the css or an image file), there are two ways of
>>> doing it. One is to simply include the relative path to the file
>>> (relative to the doc root), like:
>>>
>>> /graphics/my_portrait.gif
>>>
>>> Or you can include the full URL, like:
>>>
>>> http://example.com/graphics/my_portrait.gif
>>>
>>> My casual observation seems to indicate that the former will load faster
>>> than the latter. But has anyone done any benchmarking on it?
>>>
>>> Paul
>>>
>>>
>>
>> I am not aware if absolute URLs are faster or not (in case they are
>> there will be such a small difference you cannot probably notice) but
>> IMHO it is a bad practice to use full URLs.
>>
>> Basically because renaming directories or scripts will cause great pain
>> in the ass.
>>
>> Of course resources that are coming outside your own site are needed to
>> use absolute URLs and nobody is assuming that are useless.
>
> Agreed. But here's the real reason, in my case. We develop the pages on
> an internal server, which has the URL http://pokey/mysite.com. When we
> move the pages to the live server at mysite.com, all the URLs would have
> to be rewritten. Ugh.

My advice would be to stop coding and sort this out as soon as
possible. If your development server has a different layout to your
live server you're simply asking for trouble, especially since you're
using a front controller pattern (as evidenced in another thread).

It's simple to fix this. Add a hosts entry for mysite.local pointing
at pokey's IP. Change the server software so it has a virtual host for
mysite.local pointed at the mysite.com directory in the existing web
rooot.

This is not difficult and will allow you to solve both of the problems
you are currently asking this list about.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Full versus relative URLs

2009-02-16 Thread German Geek
Tim-Hinnerk Heuer

http://www.ihostnz.com
Mike Ditka  - "If God had wanted man to play soccer, he wouldn't have given
us arms."

2009/2/17 Paul M Foster 

> On Mon, Feb 16, 2009 at 07:39:29PM +0200, Thodoris wrote:
>
> >
> >> Here's a question related to my last post. When specifying a link in a
> >> HTML file (like to the css or an image file), there are two ways of
> >> doing it. One is to simply include the relative path to the file
> >> (relative to the doc root), like:
> >>
> >> /graphics/my_portrait.gif
> >>
> >> Or you can include the full URL, like:
> >>
> >> http://example.com/graphics/my_portrait.gif
> >>
> >> My casual observation seems to indicate that the former will load faster
> >> than the latter. But has anyone done any benchmarking on it?
> >>
> >> Paul
> >>
> >>
> >
> > I am not aware if absolute URLs are faster or not (in case they are
> > there will be such a small difference you cannot probably notice) but
> > IMHO it is a bad practice to use full URLs.
> >
> > Basically because renaming directories or scripts will cause great pain
> > in the ass.
> >
> > Of course resources that are coming outside your own site are needed to
> > use absolute URLs and nobody is assuming that are useless.
>
> Agreed. But here's the real reason, in my case. We develop the pages on
> an internal server, which has the URL http://pokey/mysite.com. When we
> move the pages to the live server at mysite.com, all the URLs would have
> to be rewritten. Ugh.
>

In that case you could change your hosts file (unix: /etc/hosts windows:
%windir%\system32\drivers\etc\hosts) and add a line with the live server's
ip like so:

123.456.789.12 www.example.com

and all your URLs would be right. When you need to check the live domain,
you can simply comment out that line with #.

;) Hope this helps a few people. Saved me a lot of grief.

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


Re: [PHP] Full versus relative URLs

2009-02-16 Thread Dotan Cohen
> I know it's been said before, but beware of relying on this value just
> for the sole purpose of deciding where things are located, as without a
> bit of error checking on it, it can be used for injection attacks and
> what-not, although, sadly, I forget the exact post recently that had the
> link that explained this issue on PHP_SELF.
>

Alternatively, $_SERVER['PHP_SELF']) could be switch()ed for known
values, and $path be set accordingly with hardcoded values.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü


Re: [PHP] Full versus relative URLs

2009-02-16 Thread Ashley Sheridan
On Mon, 2009-02-16 at 20:19 +0200, Thodoris wrote:
> > On Mon, Feb 16, 2009 at 07:39:29PM +0200, Thodoris wrote:
> >
> >   
> >>> Here's a question related to my last post. When specifying a link in a
> >>> HTML file (like to the css or an image file), there are two ways of
> >>> doing it. One is to simply include the relative path to the file
> >>> (relative to the doc root), like:
> >>>
> >>> /graphics/my_portrait.gif
> >>>
> >>> Or you can include the full URL, like:
> >>>
> >>> http://example.com/graphics/my_portrait.gif
> >>>
> >>> My casual observation seems to indicate that the former will load faster
> >>> than the latter. But has anyone done any benchmarking on it?
> >>>
> >>> Paul
> >>>
> >>>
> >>>   
> >> I am not aware if absolute URLs are faster or not (in case they are
> >> there will be such a small difference you cannot probably notice) but
> >> IMHO it is a bad practice to use full URLs.
> >>
> >> Basically because renaming directories or scripts will cause great pain
> >> in the ass.
> >>
> >> Of course resources that are coming outside your own site are needed to
> >> use absolute URLs and nobody is assuming that are useless.
> >> 
> >
> > Agreed. But here's the real reason, in my case. We develop the pages on
> > an internal server, which has the URL http://pokey/mysite.com. When we
> > move the pages to the live server at mysite.com, all the URLs would have
> > to be rewritten. Ugh.
> >
> > Paul
> >
> >   
>  
> I sometimes use something like this in my scripts for every script to 
> determine itself:
> 
> // Find what is the name of this script
> $self = basename($_SERVER['PHP_SELF']);
> 
> You can probably take advantage of the $_SERVER information so that you 
> don't need to rewrite every url you use.
> 
> Hope that helps.
> 
I know it's been said before, but beware of relying on this value just
for the sole purpose of deciding where things are located, as without a
bit of error checking on it, it can be used for injection attacks and
what-not, although, sadly, I forget the exact post recently that had the
link that explained this issue on PHP_SELF.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Full versus relative URLs

2009-02-16 Thread Dotan Cohen
>> So put it all in one place:
>>
>> > include "path.inc";
>> print"";
>> ?>
>>
>> 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.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü


Re: [PHP] Full versus relative URLs

2009-02-16 Thread Paul M Foster
On Mon, Feb 16, 2009 at 08:09:51PM +0200, Dotan Cohen wrote:

> > Agreed. But here's the real reason, in my case. We develop the pages on
> > an internal server, which has the URL http://pokey/mysite.com. When we
> > move the pages to the live server at mysite.com, all the URLs would have
> > to be rewritten. Ugh.
> >
> > Paul
> >
> 
> So put it all in one place:
> 
>  include "path.inc";
> print"";
> ?>
> 
> 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.

Paul
-- 
Paul M. Foster

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



Re: [PHP] Full versus relative URLs

2009-02-16 Thread Thodoris



On Mon, Feb 16, 2009 at 07:39:29PM +0200, Thodoris wrote:

  

Here's a question related to my last post. When specifying a link in a
HTML file (like to the css or an image file), there are two ways of
doing it. One is to simply include the relative path to the file
(relative to the doc root), like:

/graphics/my_portrait.gif

Or you can include the full URL, like:

http://example.com/graphics/my_portrait.gif

My casual observation seems to indicate that the former will load faster
than the latter. But has anyone done any benchmarking on it?

Paul


  

I am not aware if absolute URLs are faster or not (in case they are
there will be such a small difference you cannot probably notice) but
IMHO it is a bad practice to use full URLs.

Basically because renaming directories or scripts will cause great pain
in the ass.

Of course resources that are coming outside your own site are needed to
use absolute URLs and nobody is assuming that are useless.



Agreed. But here's the real reason, in my case. We develop the pages on
an internal server, which has the URL http://pokey/mysite.com. When we
move the pages to the live server at mysite.com, all the URLs would have
to be rewritten. Ugh.

Paul

  


I sometimes use something like this in my scripts for every script to 
determine itself:


// Find what is the name of this script
$self = basename($_SERVER['PHP_SELF']);

You can probably take advantage of the $_SERVER information so that you 
don't need to rewrite every url you use.


Hope that helps.

--
Thodoris



Re: [PHP] Full versus relative URLs

2009-02-16 Thread Dotan Cohen
> Agreed. But here's the real reason, in my case. We develop the pages on
> an internal server, which has the URL http://pokey/mysite.com. When we
> move the pages to the live server at mysite.com, all the URLs would have
> to be rewritten. Ugh.
>
> Paul
>

So put it all in one place:

";
?>

Full URLs don't break when users save the pages to disk.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü


Re: [PHP] Full versus relative URLs

2009-02-16 Thread Paul M Foster
On Mon, Feb 16, 2009 at 07:39:29PM +0200, Thodoris wrote:

>
>> Here's a question related to my last post. When specifying a link in a
>> HTML file (like to the css or an image file), there are two ways of
>> doing it. One is to simply include the relative path to the file
>> (relative to the doc root), like:
>>
>> /graphics/my_portrait.gif
>>
>> Or you can include the full URL, like:
>>
>> http://example.com/graphics/my_portrait.gif
>>
>> My casual observation seems to indicate that the former will load faster
>> than the latter. But has anyone done any benchmarking on it?
>>
>> Paul
>>
>>
>
> I am not aware if absolute URLs are faster or not (in case they are
> there will be such a small difference you cannot probably notice) but
> IMHO it is a bad practice to use full URLs.
>
> Basically because renaming directories or scripts will cause great pain
> in the ass.
>
> Of course resources that are coming outside your own site are needed to
> use absolute URLs and nobody is assuming that are useless.

Agreed. But here's the real reason, in my case. We develop the pages on
an internal server, which has the URL http://pokey/mysite.com. When we
move the pages to the live server at mysite.com, all the URLs would have
to be rewritten. Ugh.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Full versus relative URLs

2009-02-16 Thread Thodoris



Here's a question related to my last post. When specifying a link in a
HTML file (like to the css or an image file), there are two ways of
doing it. One is to simply include the relative path to the file
(relative to the doc root), like:

/graphics/my_portrait.gif

Or you can include the full URL, like:

http://example.com/graphics/my_portrait.gif

My casual observation seems to indicate that the former will load faster
than the latter. But has anyone done any benchmarking on it?

Paul

  


I am not aware if absolute URLs are faster or not (in case they are 
there will be such a small difference you cannot probably notice) but  
IMHO it is a bad practice to use full URLs.


Basically because renaming directories or scripts will cause great pain 
in the ass.


Of course resources that are coming outside your own site are needed to 
use absolute URLs and nobody is assuming that are useless.


--
Thodoris


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



Re: [PHP] Full versus relative URLs

2009-02-16 Thread German Geek
Should be the same as the dns request is cached and a request needs to be
made anyway.

You could argue that relative URLs are less secure, but i cannot really see
why. Well i guess someone can easier steal your source but it doesnt get
much harder with absolute URLs.

Tim-Hinnerk Heuer

http://www.ihostnz.com
Alanis Morissette  - "We'll love you just the way you are if you're
perfect."

2009/2/16 Dotan Cohen 

> > My casual observation seems to indicate that the former will load faster
> > than the latter. But has anyone done any benchmarking on it?
>
> Did you clear the cache between tests? That could explain the speed
> difference.
>
> --
> Dotan Cohen
>
> http://what-is-what.com
> http://gibberish.co.il
>
> א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
> ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
> А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
> а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
> ä-ö-ü-ß-Ä-Ö-Ü
>


Re: [PHP] Full versus relative URLs

2009-02-16 Thread Dotan Cohen
> My casual observation seems to indicate that the former will load faster
> than the latter. But has anyone done any benchmarking on it?

Did you clear the cache between tests? That could explain the speed difference.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü


Re: [PHP] Full versus relative URLs

2009-02-16 Thread Per Jessen
Paul M Foster wrote:

> Here's a question related to my last post. When specifying a link in a
> HTML file (like to the css or an image file), there are two ways of
> doing it. One is to simply include the relative path to the file
> (relative to the doc root), like:
> 
> /graphics/my_portrait.gif
> 
> Or you can include the full URL, like:
> 
> http://example.com/graphics/my_portrait.gif
> 
> My casual observation seems to indicate that the former will load
> faster than the latter. But has anyone done any benchmarking on it?

There is no difference - the browser will resolve relative URLs to
absolute URLs before issuing the HTTP GET.


/Per


-- 
Per Jessen, Zürich (-0.9°C)


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



[PHP] Full versus relative URLs

2009-02-16 Thread Paul M Foster
Here's a question related to my last post. When specifying a link in a
HTML file (like to the css or an image file), there are two ways of
doing it. One is to simply include the relative path to the file
(relative to the doc root), like:

/graphics/my_portrait.gif

Or you can include the full URL, like:

http://example.com/graphics/my_portrait.gif

My casual observation seems to indicate that the former will load faster
than the latter. But has anyone done any benchmarking on it?

Paul

-- 
Paul M. Foster

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