Reputation: 15965
Why does this work:
<?php include "includes/top_nav.php"; ?>
and why does this not work for me?
<?php include "http://localhost/includes/top_nav.php"; ?>
Upvotes: 2
Views: 124
Reputation: 37813
I see two likely reasons.
First, your server may not be configured to allow URL file access. The error in that case would read, "URL file-access is disabled in the server configuration"
If the include actually works, but doesn't include what you expect, though, that's a whole other story. In that case, the key to understand is how such a request gets processed. While executing the script you shared, your server will perform an HTTP request (to itself) and ask for the output of top_nav.php
. This is an entirely new request to the server, so the details about the original request are no longer in play.
The request will be coming from a different user (i.e., Apache) at a different IP address (i.e., your server's address, as opposed to the original client's), with different cookies, with different $_GET
data and no $_POST
data.
Thus, if top_nav.php
in any way examines server variables, environment variables, PHP variables, or any other runtime state when rendering, this will fail.
Upvotes: 2
Reputation: 27581
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see List of Supported Protocols/Wrappers for a list of protocols) instead of a local pathname.
What is the value of URL fopen wrappers on your server?
Upvotes: 0
Reputation: 178
You need to enable URL fopen wrappers as said in the documentation, and even if it's enabled, it doesn't work with Windows.
Upvotes: 1
Reputation: 5658
URL fopen wrappers is probably disabled on that server
http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Upvotes: 5