php relative path in require or include functions
Moderator: General Moderators
-
domnulnopcea
- Forum Newbie
- Posts: 5
- Joined: Mon Jun 18, 2007 5:09 am
php relative path in require or include functions
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!
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!
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.domnulnopcea wrote:when i include ('http://www.resursecrestine.ro/include/a.php)
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') ?
-
domnulnopcea
- Forum Newbie
- Posts: 5
- Joined: Mon Jun 18, 2007 5:09 am
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?
/
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?
-
domnulnopcea
- Forum Newbie
- Posts: 5
- Joined: Mon Jun 18, 2007 5:09 am
it will not work
i have tried ...but DOCUMENT_ROOT will take a path from the subdomain...and i want to acces the root/include
-
domnulnopcea
- Forum Newbie
- Posts: 5
- Joined: Mon Jun 18, 2007 5:09 am
meaning http://subdomain1.resursecrestine.ro/index.php will request
?resursecrestine.ro
----include
-------a.php
-------b.php
----subdomains
---------subdomain1
--------------index.php
-
domnulnopcea
- Forum Newbie
- Posts: 5
- Joined: Mon Jun 18, 2007 5:09 am
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?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Code: Select all
include(dirname(__FILE__) . '/../../foo/bar.php');