Click to See Complete Forum and Search --> : PHP Include
tims15
11-07-2005, 04:50 PM
How do I have an php include that includes a page in the top level, in a page that is in a folder? ie. In page www.domain.com/FOLDER/page.php have the include www.domain.com/page2.txt. www.domain.com/page2.txt also has includes for www.domain.com/page3.txt (I hope you understand!)
NogDog
11-07-2005, 05:13 PM
If I understand correctly, probably the surest way to do it would be to make each of the includes:
include($_SEVER['DOCUMENT_ROOT']."/page2.txt");
That way, regardless of what the current working directory is, the included file will found based on its relation to the the document root.
chazzy
11-07-2005, 05:13 PM
what happens if you just use include('http://www.domain.com/page2.txt');
tims15
11-08-2005, 10:33 AM
I tried both and got this error message:
Warning: main(/page2.txt): failed to open stream: No such file or directory in /home/tims15/public_html/folder/signup.php on line 1
Warning: main(/page2.txt): failed to open stream: No such file or directory in /home/tims15/public_html/billing/signup.php on line 1
Warning: main(): Failed opening '/page2.txt' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/tims15/public_html/billing/signup.php on line 1
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/tims15/public_html/billing/signup.php:1) in /home/tims15/public_html/billing/signup.php on line 153
All pages and folders were existant of course
Sheldon
11-08-2005, 02:24 PM
Post the code to there you are trying to include the page and start the session.
How come the directories change? If the flder is only one level above you could try
include('../page2.txt');
PanrovianMonk
11-09-2005, 08:04 AM
I had a similar problem with my web host. I have PHP files in a shared directory and call them from a sub-directory. However, some of the PHP files in the shared directory include each other. I couldn't use the domain, as I'm not at the top level (like tims15) and I didn't have access to modify the php.ini file.
I had a file subphpfile.php in /misc like:
<?php include('../lib/phpfile1.php'); ?>The file phpfile1.php was located in /lib and included phpfile2.php:
<?php include('phpfile2.php'); ?>My solution was to modifiy subphpfile.php to:
<?php
ini_set('include_path',ini_get('include_path').':../lib:');
include('phpfile1.php');
?>
The problem was that phpfile1.php executes it's include as if it's in the /misc directory and would not find phpfile2.php. By changing the include_path, it lets the system find the files for you.
I hope that this helps.
tims15
11-10-2005, 02:04 PM
I tried it and it worked.
Thanks everyone for your help!