William Maloney William Maloney - 4 months ago 18
PHP Question

PHP include call fails

I'm writing a series of web pages in which I want to modify the format in which a time-of-day is displayed. I've written a PHP function to do that, and the function works perfectly when the it is in the same file as the rest of the code. However, I want to do this conversion process in several related files, so I"d like to put the function in an external file that I can simply "include" where needed. TBut I can't get tghe "include" bit to work.

Here's the code I'm using for the inclusion process:

<?php
include 'http://www.northcentralflaa.org/header.html';
include 'http://www.northcentralflaa.org/d.sysadmin/f-time.php';
?>


The header file (in the first "include" line) shows up with no problem, but the f-time.php file is not brought in.

The error_log file tells me this:


"[07-Jul-2016 11:12:03] PHP Warning: include() [function.include]: Failed opening
'http://www.northcentralflaa.org/d.sysadmin/f-time.php' for inclusion
(include_path='.:/usr/lib64/php:/usr/share/pear') in
/home1/northce1/public_html/d.sysadmin/admin-portal.php on line 19"


This appears to be telling me - in "(include_path='.:/usr/lib64/php:/usr/share/pear')" - that the system is looking for some files in a sub-directory that, as far as I know, does not exist. But, as I said, the first "include" statement works perfectly.

FWIW, I've also tried the HTML SSI inclusion process:

:
<!--#include file="http://www.northcentralflaa.org/d.sysadmin/f-time.php" -->


(outside the php brackets, of course), and I've tried both processes using a relative path instead of absolue path, both with and without the leading dot-slant. I've checked my spelling of directory and file names. And even though the function works perfectly when written in the base web-page file, I've also tried commenting-out the entire function (in the f-time.php file) and importing only a line saying

echo "The file was imported";


Even that fails to show up. Any ideas where I can look further for resolution?

Answer

I found a fix. I cannot fully understand why it works, but if I re-write that second include commend as

include $_SERVER['DOCUMENT_ROOT'] . '/d.attic/f-time.php'; 

it works as expected. (The re-write was NOT required of the first include statement, which leaves me mystified.)