Jump to content

how to handle includes within include files


Vikas Jayna

Recommended Posts

I've recently upgraded from PHP 4.3.2 (cgi) to PHP 5.2.4 (cli). As a result I'm facing the following issue while running php from the command line:

 

I execute a file a.php in my home directory as

php -q a.php

the file a.php includes a php file like this

include ("/var/www/html/b.php")

the file b.php further has includes like

include("c.php")

 

now the file c.php is located within /var/www/html but the newer php version looks for the file in my home directory while the older version looks for it in /var/www/html

 

A workaround for this that I've used is to change the current directory using the chdir function to /var/www/html and it works but this process becomes quite cumbersome if the script is having a number of includes this way from separate directories.

 

Is there any configurational change that can be done in php to avoid these issues?

Hi,

 

include means actually the whole file is included into the calling php page. So if you include var/www/html/b.php  file in  a.php

then in a.php the whole file what you are calling from the path it fetches and includes into the a.php file. and if you call again c.php in the file var/www/html/b.php, it looks for the file which is at in the a.php directory, so you will get a warning message.

 

In the same way if you run the var/www/html/b.php file directly in the command prompt then for c.php it looks at var/www/html directory.

 

I hope there is no other way to giving of relative urls, It is much better to give relative urls.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.