Php - header file - relative paths problem?

Do not use static value for path instead define a constant for document root and use that constant define('ROOT_PATH',$_SERVER'DOCUMENT_ROOT') While including files you can use this constant include ROOT_PATH. '/some_dir/file.php.

Do not use static value for path instead define a constant for document root and use that constant define('ROOT_PATH',$_SERVER'DOCUMENT_ROOT'); While including files you can use this constant. Include ROOT_PATH. '/some_dir/file.php.

Thanks for the answer. So in which file I need to define the ROOT_PATH? Header.

Php will do? – Anji Apr 27 at 8:43 @Anji: You should have one config file which will hold configuration variables and will be included as soon as your application initiate. – Shakti Singh Apr 27 at 8:45 won't that be the same problem including config file?

– Anji Apr 27 at 8:49 @anji: No, That could not be you place your config file in document_root directory and can include directly like include 'config. Php' The include of config file should be in your root index. Php file – Shakti Singh Apr 27 at 8:51 okay I see it now.

Will give it a try. Thank you. – Anji Apr 27 at 8:54.

You have bad architecture in your application. Try to search info about MVC. This answer may be useful: What is good (neat) architecture in programming?

So: change architicture, use autoload.

Thanks for the links. Will read about MVC – Anji Apr 27 at 8:52.

Relative paths are relative to the current working directory (cwd). If you just include another file that cwd does not change. If you want to have paths that are (somewhat) relative to the current script file path you can use e.g. Require dirname(__FILE__).

'/some_dir/file. Php'; or as of php 5.3 require __DIR__.'/some_dir/file. Php'; see also: docs.php.net/language.constants.predefined.

If I understood your question right, you just would like to know the root folder your application without the need to hardcode it. The easier way is to define a constant as Shakti has answered. However, you could actually have a file with a unique name such as "foobar" in the root folder, then walk up the tree from current directory until you find foobar.

Sorry I could not get what "foobar" file is about. – Anji Apr 27 at 8:47 Say you have "foobar" in /var/www/public_html/, and your cwd is unknown, but surely something like /var/www/public_html/my/current/folder/. After you got your current working directory, while foobar is not found go up one level.

You got your root directory, when you found your foobar file. – Mike Han Apr 27 at 9:05 yeah.. so basically foobar is used to get the root directory. Thanks – Anji Apr 27 at 9:14.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions