View Full Version : Nice & Easy about php includes.
04-10-2003, 01:06 AM
This is what I'm attempting to do.
On my first /index.php. I want to include my toplist. Which is in a sub directory called /toplist/index.php
I have added the code
<?php include "/toplist/index.php"; ?>
But I'm recieving errors for another file that that index.php needs.
Here is my front page - http://www.font-factory.com
Here is the toplist I wish to include - http://www.font-factory.com/toplist/index.php
In the toplist directory contains other directories needed to run the toplist.
Do I need to use require, or rewrite the whole (spanish) script!!?? :(
Basically I wish to keep all the toplist scripts relative to the Index.php even though it will be called from a directory above it (If that makes sense?).
I need to get this sorted ASAP as my members are waiting to rejoin my new toplist!
Please help me....... :)
Fanx in Advance.
Admin of Font-Factory.com
04-10-2003, 01:56 AM
This is what they are saying for the open_basedir error on php.net
"Limit the files that can be opened by PHP to the specified directory-tree. This directive is NOT affected by whether Safe Mode is turned On or Off.
When a script tries to open a file with, for example, fopen or gzopen, the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to open it. All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink.
The special value . indicates that the directory in which the script is stored will be used as base-directory.
Under Windows, separate the directories with a semicolon. On all other systems, separate the directories with a colon. As an Apache module, open_basedir paths from parent directories are now automatically inherited.
The restriction specified with open_basedir is actually a prefix, not a directory name. This means that "open_basedir = /dir/incl" also allows access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: "open_basedir = /dir/incl/"
Opomba: Support for multiple directories was added in 3.0.7.
The default is to allow all files to be opened. "
04-10-2003, 04:53 AM
try this :
<?php include("./toplist/index.php"); ?>
It will probably work. At least this is what i use with no problems at all.
04-10-2003, 06:42 PM
Why not just:
<?php include("toplist/index.php"); ?>
04-10-2003, 07:20 PM
I have tried all 3 of these suggestions and it does'nt want to work. :(
Has anyone got any other ideas?
I can't understand why these are working for others and not me! :(
At the moment I have this in my page -
<table width="100%" border="0" cellpadding="15">
<font size="2"><b>Top Five FontSites</b><br>
<?php include $_SERVER ['DOCUMENT_ROOT']."/toplist/index.php"; ?>
04-10-2003, 07:22 PM
include $_SERVER 'DOCUMENT_ROOT']."/toplist/index.php";
//You're missing the "["
04-10-2003, 07:33 PM
Sorry. That was a typo on my behalf!
That script IS actually correct on my page though, (still doesn't work!) :(
04-10-2003, 07:39 PM
Make sure there's no space between $_SERVER and the "["
Try this. Instead of "include" put echo and see what prints out. If you think its in the right directory, then try
and see if it returns true (it should print out 1). If it doesn't, then the file doesn't exist there and there seems to be a problem where you think its located.
04-10-2003, 07:40 PM
If that doesn't work, what version of php are you using?
04-10-2003, 08:06 PM
I placed that code and have got a 1 (http://www.font-factory.com)
I thought this would be nice n easy! LOL
Shows what I know! :D
04-10-2003, 08:40 PM
Okay, so we know the file does exist.. I recommend you check your code for the toplist/index.php and see that nothing stands out that might intervene with the main page.
Like remove extra <html> tags etc. of if you have a cookie on that page, make sure its right at the beginning etc.
In fact, try it with another file, which just has some simple text in it, and carry on from there.
04-10-2003, 09:10 PM
I know that the toplist/index.php page is being added to the main page. But it's the pages connected to the toplist/index.php I'm having problems with.
The file index.dat for example cannot be found by the toplist/index.php because it effectively has been loaded in the root of my site.
I'll try to explain a little bit more in detail
In Front Page is an include for the Toplist Page.
In the Toplist Page other files are needed.
Becaues the file toplist/index.php had been loaded onto my Main Page (http://www.font-factory.com).
The index.dat file is no longer located at data/index.dat (which is what is stated in about a million different places) it is now in toplist/data/index.dat
There are loads of other files related to this toplist and to change them all would be a complete nightmare. Especially as I'm a PHP nOOb! :)
04-11-2003, 12:45 AM
Gotcha, then its an easy fix.
Do the same thing you did to call the first file for all the includes:
Takes care of everything.
04-17-2003, 02:54 PM
That is what I'm trying to avoid doing.
The whole script has loads of different different files, that are included into each other to change the lot would be extremely hazardous.
Is there any other way of doing it?
04-17-2003, 03:19 PM
What about the include_path() function. Is that what I need? Can anyone confirm that his may work please?
This is getting somewhat frustrating now. Please assist! :)
04-17-2003, 07:23 PM
1. if you do the way I suggested, you won't have to worry about changing anything if you changing servers.
2. Its only messy initially, once its typed, its done.
3. What do you mean by "hazardous"?
4. I wouldn't recommend include_path as what it does is make the server look in the directories one by one for the file you are looking for, which means it will take a longer time to find it (for instance, if you have 8 different directories -> and your file is in the 8th one, include_path will have to go through the first 7 until it reaches the right directory, and then after that, has to find the file in the 8th one). Another thing is if you are changing your servers in between from UNIX to Windows, so that would mean you would have to change the way you call in include_path().
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.