Question:
php include_path, require, HELP!!!!!!!?
TheHermit
2007-09-08 01:14:55 UTC
hi there

i'm making a php-mysql web application and it works fine, EXCEPT... my php include(), require(), etc. doesnt work!! it works fine on the local machine but once its up on the server, it just disappears.. the url is http://www.hygree.com/ . can you tell me what EXACTLY i have to write within the include() to make this thing work. the hosting pricks wouldnt gimme access to change the php.ini file but you can see it here:
http://brainpulse.info/phpinfo.php

you'll notice that its a linux system and the include_path is .:/usr/share/pear . now i'm not much of a linux user so i have NO clue if pear refers to the fruit we all enjoy eating or someone's SICK idea of a joke. yes i'm frustrated. i've been trying i tell you. could use some help here. and please, don't be vague! thanks in advance..
Three answers:
anonymous
2007-09-08 07:58:25 UTC
You should use the relative-to-script path to the file, or you can use an absolute path, as you would in any other HTTP document.



Suppose, for example, the root directory of your Web site is named public_html; that is, your home page, named index.php, is in public_html.



Suppose you have a subdirectory named includes, and a file in there named header.php.



To include that file in your index.php, you could do it one of two ways:



1. path relative to document: require_once( "includes/header.php" );

2. path relative to root: require_once( "/includes/header.php" );



(I prefer to use require_once(), since it kills the script on failure and prevents accidental function poisoning.)



The difference between using a path relative to the root versus relative to the document is that a root path will work regardless of where the document containing the include is located, while a document path can get messed up if the including document's location changes.



Let's suppose you have a page in your root directory named mypage.php. Suppose again that you have a subdirectory named includes that contains a document named header.php.



You include header.php using document-relative notation:



require_once( "includes/header.php" );



Now suppose you move mypage.php to the includes directory and call it.



You won't see the included page, because in document-relative addressing, mypage.php expects to move down into a directory named includes, then find a page named header.php and include it.



But since mypage.php is IN the includes directory, it can't find a subdirectory named includes within the includes directory itself. So, since it can't find that subdirectory, it dies.



But suppose you used root-relative addressing for the mypage.php include:



require_once( "/includes/header.php" );



This tells mypage.php, "look to the root of the Web site. Then, find a subdirectory named includes, and include header.php from there."



No matter where you put mypage.php, as long as it's in your Web directory or some subdirectory of the root Web directory, it will be able to resolve the path, because it looks for everything relative to the root directory, not relative to itself.



You need not worry about the PEAR path. PEAR is a way to extend PHP and its ability to handle other programs -- for example, there are PEAR modules to work with different databased, to work with XML, etc.



Including your own files has nothing to do with PEAR, so ignore that.
ufo_josh
2007-09-08 01:35:50 UTC
What are you actually trying to include?



the function include(); in PHP requires you to enter a variable.



For example if I wanted to include a page called variable.php I would use the following code:



include(variable.php);





If I was to include a file called myfile.php which is in a sub-folder called myfolder I would use the following code:



include(myfolder/myfile.php);



If that doesn't work try placing quote marks (" ") either side of the variable e.g.



include("variable.php");



or



include("myfolder/myfile.php");





Should be of some use to you. If not read through the source (see below).
?
2016-10-18 11:33:39 UTC
do not use unquestionably the course with the force letter, attempt the relative course. if t.own living house page is interior the comparable folder as attempt.own living house page, attempt require(t.own living house page) If attempt.own living house page is interior the htdocs folder, attempt require(/load/alley/t.own living house page) EDIT - final analysis, you may not use a force letter interior the path.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...