I am trying to include a file 'header.php' that is in

http://ewh.ieee.org/r1/schenectady/

From a file in
http://ewh.ieee.org/r1/schenectady/Events/

if I do:

<?php include '../header.php';?>

it works fine, as expected. However, if I do:

<?php include 'http://ewh.ieee.org/r1/schenectady/header.php';?>

it does not work (the header is not displayed).

Can anyone explain why this wouldn't work?

Thanks,

David

Recommended Answers

All 5 Replies

Check php.ini and make sure the URL_fopen_wrappers is enabled.

Where is php.ini? I only have ftp access to this server, so I doubt I can change (or even see) that file. Is there anything else I can do?

Member Avatar for diafol

The 'absolute include' is trying to access webroot. A dirty solution would be:

include($_SERVER['DOCUMENT_ROOT'] . "/r1/schenectady/header.php");

However, I've recently learned that this isn't the best way to do things.

A relative solution would be best if you're not accessing the include from another include. That is, if your include statement exists inside a file which is itself an include file. If so, you'll have to reference it relative to the 'ultimate parent page'. An added complication to relative references is if a number of files, in different locations include a file, which includes another file. That's when an absolute reference can save your bacon.

Great, it works. A bit awkward/annoying, but it works :) Why do you say "this isn't the best way to do things"?

Member Avatar for diafol

I think it's because some virtual paths can differ from the expected. I don't really know to be honest, I was told this by somebody (far more proficient than me) recently. It's always worked for me though.

There was talk of using

dirname(__FILE__)

for the webroot, but that only gives me the path for the current document, not the path include file. So, I can't see how to use it. Anyway, hope somebody out there can elucidate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.