...

View Full Version : change my php include path



Armondo
03-27-2007, 03:51 PM
how would i go about changing my default include path to the root of my site? what i want to do is when i type in
include('some/file.php'); and the page i use the script in is "dir/example/script.php" it doesn't look for "some/file.php" in "dir/example/script.php/some/file.php" it goes to the root of my site "/" then looks for "some/file.php". so it would go like this:
root -> some/ -> file.php
instead of:
dir/ -> example/ -> script.php-> some/ -> file.php
if i could get some help on this it would be great :)!

arne2
03-27-2007, 04:28 PM
maybe with $DOCUMENT_ROOT?
so like this:

<?php
include($DOCUMENT_ROOT . "/page.php");
include($DOCUMENT_ROOT . "/map/page.php");
I think you'll get the picture..
I don't know if it's what you need but.. you can always try.
Good luck!

iLLin
03-27-2007, 09:57 PM
set_include_path('/home/httpd/...');

//include files

restore_include_path();


Or just include the file absolutely.



include('/some/file.php');

Armondo
03-28-2007, 12:19 AM
when i use
include_once('../statistics.php'); it works... but when i use
include_once('/statistics.php'); it returns these errors:
Warning: main(/statistics.php): failed to open stream: No such file or directory in /home/content/A/r/m/Armondo13/html/usersys/userlook.php on line 9

Warning: main(): Failed opening '/statistics.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/content/A/r/m/Armondo13/html/usersys/userlook.php on line 9 i tried changing the include path in my php.ini file with this code:
include_path = /usr/local/lib/php/home/content/A/r/m/Armondo13/html
and it like...screwed up this code on my page:
<?php
if(isset($lookupuser)) {
$dbcnx = mysql_connect("*", "*", "*");
mysql_select_db("flashanims_db");

$query = "SELECT * FROM users WHERE username='$lookupuser'";

$result = mysql_query($query) or die(mysql_error());

while($r = mysql_fetch_array($result)){
$usernum = $r['id'];
$useremail = $r['email'];
$userpoints = $r['points'];
$userjoin = $r['joined'];
$userrank = $r['rank'];
$userlastseen = $r['lastseen'];
$yr = substr($userlastseen, 2, 2);
$mo = substr($userlastseen, 5, 2);
$da = substr($userlastseen, 8, 2);
$hr = substr($userlastseen, 11, 2);
$min = substr($userlastseen, 14, 2);
if ($hr > "11") {
$x = "12";
$timetype = "PM";
$hr = $hr - 12;
}else{
$timetype = "AM";
}
}
print "Username: $lookupuser<br/>Rank: $userrank<br/>Points: $userpoints<br/>Last Seen On: $mo/$da/$yr $hr:$min<br/>User Number: $usernum<br/>Member Since: $userjoin<br/>Email: $useremail<br/>";?><br/><span>Look up a username:</span><br/>
<form action="userlook.php">
<input type="text" name="lookupuser" />&nbsp;<input type="submit" name="Search" />
</form> <?php } else { ?>
<span>not found</span>
<?php }
?>

iLLin
03-28-2007, 01:08 AM
Ok let me explain this to you. You can include "relative" or "absolute" files into your pages.

Relative means an include relative to your current location. For example lets say you are in the folder web directory where your index file is located and you do:


include('somefile.php');


That will search for that file in the same folder as your index file. "Relative to your current location.

Now lets say you do this:


include('/somefile.php');


Notice the slash as the beginning. This tells the server to start from ground zero "/".

So from looking at your error your index file is located here:
/home/content/A/r/m/Armondo13/html/index.php

So if you are in the directory /html, and you include a file relatively, it will look for that file in that directory.

If you add the slash in front, it will basically back all the way up to the beginning of your directory tree. It will search in the same directory as "home" is located.

Now what I showed you with the


set_include_path('/home/...');


That will basically change your "relalative" location for includes. I dont advise in using this unless you have a good reason. For example I run a server with ALOT of websites that plug into a CRM. Now since there all on the same server I can change my include path to that of the file locations for all my files in the CRM and include them relatively so they will act right as they include files within there own files... Sounds complicated but I wouldn't worry about that until you run into a situation like that.

If you need more clarification let me know.

Armondo
03-28-2007, 01:29 AM
i guess that makes sense a little bit...so your saying if i use absolute it backs up all the way to my home directory or the html dir where my root is? cause that is what i want...i don't want to to go relative to the current page i'm on...i want it to go to the root of my site and then search from there.

Inigoesdr
03-28-2007, 03:54 AM
i guess that makes sense a little bit...so your saying if i use absolute it backs up all the way to my home directory or the html dir where my root is? cause that is what i want...i don't want to to go relative to the current page i'm on...i want it to go to the root of my site and then search from there.
Absolute means you need the full path to the file. Relative means relative to the current directory of the file.

Armondo
03-28-2007, 04:05 AM
I UNDERSTAND THAT. NO NEED TO USE BOLD LETTERING :). what i am saying is that if i use absolute file inclusion does it search my root up, or what?

Inigoesdr
03-28-2007, 04:07 AM
Yes... hence the "full path".

iLLin
03-28-2007, 04:08 AM
Most people use relative includes. So lets put out a document tree:

/home/content/A/r/m/Armondo13/html/

That is your html directory where you are uploading your files.

if you are in this directory

/home/content/A/r/m/Armondo13/html/usersys/config.php

and you want to backup to yoru html directory you would do this

include('../somfile.php');

The dot dot backups up 1 directory and looks for the file. You can do that as much as you want.

include('../../../somefile.php');

Now it would look in your 'm' directory...

Absolute means you have to provide the FULL path:

/home/content/A/r/m/Armondo13/html/somefile.php

Just stick with relative URL's until you get a better understanding :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum