Forum Moderators: coopster
Also, I notice that if I do something like
<?php
include /includes/header.php;
?>
it won't work.
But if I take away the first slash (includes/header.php), it works. Why is that? I mean, shouldn't all absolute links (that leave out the mydomain.com part) start with a slash?
From what I know, your server will check in the current folder (where your php file which call the include is located), if not found, it will check from the root.
The thing is to set yourself the location of your ionclude folder by using php_ini command
$http_dir="your_domain_name";
$docserver_root=str_replace("/","\\",$_SERVER['DOCUMENT_ROOT']);
ini_set("include_path", ".;$docserver_root."\\".$http_dir."\include");
It is possible that your host do not authorise you to modify you ini setting, in such case get in touch with them to know about the current setting or go to your info.php page.
Then, when you call an include, you just type
include_once ("my_include.php");
About the diffenence between include_once, include and request_once, do not remember... I always use include_once though.
require() produces a fatal error. An error is also printed by default, but it interrupts script execution. Besides seeing a warning message on your page, require() also halts your page's execution after the require() function returns. So even though the page is supposed to display a table after the require() part, you wouldn't see the table, because the execution has already been halted by require().
include_once() and require_once() work the same as include() and require() except that they guarantee that the file has only been included once.
If you have the following code in the same page:
include_once("a.php"); //includes a.php
include_once("a.php"); //doesn't include a.php again since it has already been included.
The above explanation is found at php.net.