Page 1 of 1

Relative Path versus Absolute Path

Posted: Tue Jan 01, 2008 11:18 pm
by devendra-m
Is there any advantage of using absolute path over relative path

like

Code: Select all

require('http://www.domain.com/test/test.php');
and

Code: Select all

require('test/test.php');

Posted: Tue Jan 01, 2008 11:44 pm
by RobertGonzalez
FYI, your first example is not a full path, it is an URI. A full path would be something like

Code: Select all

<?php
require '/full/path/to/some/file.php';
?>
A relative path would be something like:

Code: Select all

<?php
require 'file.php';
?>
or

Code: Select all

<?php
require '../file.php';
?>
To answer your question, there is no real advantage to using either. When using a URI you have to have certain settings turned in php.ini in order to open files over HTTP

Posted: Wed Jan 02, 2008 12:14 am
by devendra-m
require('http://www.domain.com/test/test.php');

but it also works. Is it wrong practice to use path like this

Posted: Wed Jan 02, 2008 12:47 am
by RobertGonzalez
I wouldn't do it that way. If it is on the server, call it from the server, not from the web.

Posted: Wed Jan 02, 2008 1:01 am
by Kieran Huggins
devendra-m wrote:require('http://www.domain.com/test/test.php');

but it also works. Is it wrong practice to use path like this
When you include a file that way, PHP will send an HTTP GET request to your server to retrieve the contents of the file, just like a browser would. That means that Apache and PHP will process the file and deliver the processed output to your "require" statement.

When you include a file from the filesystem, the entire, unprocessed contents are dumped directly to your script.

Posted: Fri Jan 04, 2008 5:08 pm
by alex.barylski
An advantage to using relative paths to absolute paths???

Relative paths usually result in more portable code...you can move entire folders around without having to update a ton of paths in your source code.

Re: Relative Path versus Absolute Path

Posted: Mon Jan 14, 2008 6:50 am
by webspider
devendra-m wrote
require('http://www.domain.com/test/test.php');

but it also works. Is it wrong practice to use path like this
may arise an issue of code injection. turn off allow_url_fopen and allow_url_include in php.ini