Page 1 of 1
php relative path in require or include functions
Posted: Mon Jun 18, 2007 5:13 am
by domnulnopcea
can anyone help me???
I have a file named index.php and in this file I include a file from /include folder named a.php! in the /include directory i have a file named b.php! and when i try to include this file from a.php like require ('./include/b.php') it will not include it. The problem is that i have many subdomains!
and from subdomain cantece.resursecrestine.ro i try to include a.php witch is in the /include folder from the root of the site....
when i include ('
http://www.resursecrestine.ro/include/a.php) it will include a.php but not b.php which is in the same /include folder from the root. at the same level with a.php
can anyone help me here?
i will really appreciate!
thank you!
Posted: Mon Jun 18, 2007 5:24 am
by volka
you send a new http reuest to the webserver just like a browser does thus starting a new php instance that is not connected to your including script.
There is somethin called current working directory. A relative path is relative to this cwd. php set's the cwd to the directory the "primary" script resides in. Therefore the cwd will be /include/ for the php instance executing a.php. And therefore include('include/b.php') tries to include /include/include/b.php
Why do you use include('
http://..../include/a.php') ?
Posted: Mon Jun 18, 2007 5:31 am
by domnulnopcea
this is the structure of my website
/
include
--------- a.php
---------- b.php
subdomains
---------- subdomain1
---------- subdomain2
when i am executing scripts from subdomain1 let's say index.php i include in index.php something like this include(
http://site.ro/include.a.php)..i use the http form because otherwise it will not include it...
i tried to do something like this require(./../include/a.php)...but this will not work...i do not know why..maybe it it smoething with my apache web server that i do not know how to configure....
all i want to do is to make visible the include folder in my subdomains...to share it...so i could acces it...
can you help me?
Posted: Mon Jun 18, 2007 5:37 am
by Gente
Use absolute pathes.
$_SERVER['DOCUMENT_ROOT'] should help you with your problem
it will not work
Posted: Mon Jun 18, 2007 5:39 am
by domnulnopcea
i have tried ...but DOCUMENT_ROOT will take a path from the subdomain...and i want to acces the root/include
Posted: Mon Jun 18, 2007 5:39 am
by volka
Hm, now you're confusing me. Exactly what do you mean by subdomain? Because site.ro is no subdomain of resursecrestine.ro
Posted: Mon Jun 18, 2007 5:43 am
by domnulnopcea
please forgive me for the confusion
the root is resursecrestine.ro....
i have many subdomains in the subdomain folder of the resursecrestine.ro folder!
the structure is
resursecrestine.ro
----include
-------a.php
-------b.php
----subdomains
---------subdomain1
--------------index.php
Posted: Mon Jun 18, 2007 5:50 am
by volka
meaning
http://subdomain1.resursecrestine.ro/index.php will request
resursecrestine.ro
----include
-------a.php
-------b.php
----subdomains
---------subdomain1
--------------index.php
?
Posted: Mon Jun 18, 2007 5:52 am
by domnulnopcea
in index.php from subdomain1 i require a.php from root...and in a.php i require b.php...
how can i include a.php without the up-level going model (./../../../) and without the http:// form
Posted: Mon Jun 18, 2007 5:53 am
by volka
Please answer my question. Does a request for
http://subdomain1.resursecrestine.ro/index.php invoke the script that is marked red in the directory structure?
Posted: Mon Jun 18, 2007 7:22 am
by superdezign
Code: Select all
include(dirname(__FILE__) . '/../../foo/bar.php');
dirname(__FILE__) starts at the file's current directory.