Hello there, I have searched the forums for this topic and found a few similar problems but none much like mine.
My problem is with using the <?php include('info.php') ?> in files located in folders.
For example;
Here is the file I want to include..
www.example.com/info.php
Here is the page that should display the file
www.example.com/folder/page.php
Can I still write <?php include('info.php') ?> or do I need to do something special?
A page on the root directory will load fine, but soon as I use the include in a folder it will not show up and I get an error.
Do I have to format the include differently? I have tried all kinds of ways and can't seem to figure it out. These files I want to include save a lot of time because they are for menus and promotions etc.
If this file www.example.com/folder/page.php has to call a file residing at the root, then you need to show the path where it can find it - like so :
<?php include('/info.php') ?>
I just tried that and nope I still get an error. It works at the root but not from the folder. I set it all up as a test and the folder has no fancy permissions or anything just a straight naked page with an include. In my test I'm using my navbar.php file which is currently working on many other pages and this is what it pukes out: (I censored part for security, but you get the drift)
Warning: main(/navbar.php) [function.main]: failed to open stream: No such file or directory in (my test folder) on line 8
Warning: main(/navbar.php) [function.main]: failed to open stream: No such file or directory in (my test folder) on line 8
Warning: main() [function.include]: Failed opening '/navbar.php' for inclusion (include_path='.:/usr/share/php4:/usr/share/php') in (my test folder) on line 8
So what do you think? Am I just doing something so simple wrong I cant see it? LOL
Edit the PHP configuration file so that you specify where the default file is located. If the include doesn't find it in the current directory, it will look for it wherever you have specified in the PHP configuration file.
ok so I've used the info.php file, seen my info, located my file downloaded it, and checked it out. I'm not real sure what the instructions want me to do to it though. It does in fact talk about what I'm trying to do though and thats more info than I could find, Thanks bhartzer!
I'll keep searching around, look up some of the terms they use on that site. Everyones suggestions are still welcome, I haven't got this fixed just yet.
Bah! I get nothing from this Wrappers code. Maybe I'm missing something but I'm not going to get involved with a new project until I figure out my current problem.
As to the fist suggestion you made bhartzer, its useless to put a info.php file into each folder because when its time to update that will give me a info.php to update for each page i have, and thats not going to save me very much time. There isn't a lot of folders right now, only 8 but each of them have their own page that needs to include the file. The structure of the folders isn't my choice and must be like that for another script I'm running which have pages I can modify to match my current theme with headers and footers etc.
I don't know why this can't be as simple as Prowler suggestion, that would make this a lot less time consuming.
All of my includes reside in a folder called "includes"
My htaccess file then lists, on one line, the path to follow for all includes.
Looks like this:
After that, the code I place on the actual page where I want the include to show up is as follows:
This should work, as it's the combo I currently have live. Try moving the files to include into their own folder and see if it like that better. It really shouldn't matter, but you never know...
I just get an internal server error, does my htaccess file have to be set to a certain permission?
I can actually include files from folders, worked fine as it was with out the htaccess part I just found out. However the pages in the folders still will not load the files. If the folders or the page are set to a certain permission will that stop the include script from working? (I've tried both ways, and with fresh test folders, i'm just curious)
.htaccess file can be left at the default permission value.
From the sanitized error report you have given, it seems obvious that the server is looking in the wrong place for the elusive info.php
A lot of things depend on your server configuration and at times things might change at the run time. So we are taking a peek in the dark at the moment as I can't see other factors.
Try another simple method: -
Put a ../ to jump back one level in the path like so:
<?php include('../info.php') ?> Assuming that your info.php resides one level above your test directory.
It will. A caveat is in order here. The include files should preferably reside in the root or a directory directly from root, so that any file downstream can follow the path to the root without much problem.
Well here's the good and the bad...
The good, you've fixed my problem, and it all works perfectly even from the 4th folder.
The bad part is on the particular page that I want it to work on, it won't because of the script that opens that page. I don't know cgi at all so it will be tough to fix I imagine.
If anyone is curious what this is all about, the script is for an online tarot card reader. There are several card layouts (the folders I had to go through) and then brief and long card readings (more folders). Then there is the index, which asks you your question about your fortune. When you click submit that runs the script and gives you a new page with your reading on it. This is the page where I was trying to use includes from. When the site is a little more complete and a little less plain, I'll link it to you all.
You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
You have not yet logged in, or registered properly as a member
You are a member, but no longer have posting rights.
This is a private forum, for which you do not have permissions.
If you are a recent member, it's possible that you simply have not yet confirmed your account. Please
check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions
contained within.
If you are still experiencing problem, please read the
Login Assistance
Article for some advice on what may be causing your login not to work properly.