Forum Moderators: coopster

Message Too Old, No Replies

other options to <? include?>

         

humpingdan

5:31 pm on Apr 7, 2004 (gmt 0)

10+ Year Member



im currently using the include statement on one of my website, i was wondering if there are any other options to use in php,

i simply want to display the contents of a text file in a html page, problem is ive handed this code over to a friend to use and the web host he uses produces an error because the include is directed sumwhere else? or sumthing like that his phpo is configured differently to mine?

what are the other options?

$text = "wordpad/tagline.txt"

echo ('$text');

i dunno im php newbie!

Thanks

coopster

7:10 pm on Apr 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There are a number of ways to make it easier on yourself. One option would be to have some sort of configuration script that sits on the public side of the site in the root that sets the include path...

config.php

// For UNIX: 
ini_set('include_path', ini_get('include_path') . '.:' . $_SERVER['DOCUMENT_ROOT'] . '/../includes/');
// For Windows (paths are separated by semicolons, not colons):
ini_set('include_path', ini_get('include_path') . '.;' . $_SERVER['DOCUMENT_ROOT'] . '/../includes/');

Now you could keep the includes in their own directory, below the root. You can organize them however you want. For example you could have subdirectories within the main "include" directory separating scripts logically. Then, when you want to include any scripts, just include the config.php script first, then the rest will be found below the root, protected from the general public.

include($_SERVER['DOCUMENT_ROOT'] . "/config.php"); 
include("myscript.php");
include("subdir1/mynextscript.php");
include("subdir2/andyetanother.php");

Your code becomes much more portable at this point.

humpingdan

7:32 pm on Apr 7, 2004 (gmt 0)

10+ Year Member



lol sorry i really dont understand that at all!

is there not just another function for me to pull in another file into my html?

ergophobe

8:37 pm on Apr 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What coopster is giving you is a method so that when you transfer your script from one server to another, it will run without modification (provided the target server is one you have anticipated).

The idea is to take a combination of built-in variables and server-specific paths and make sure that, on all servers you plan to run on, PHP will correctly resolve the paths.

I don't know whether that helps at all.