include() through HTTP?
Can I include file through HTTP? I tried the example below from http://uk2.php.net/function.include
but it is def not working on my localhost.
// Won't work; file.txt wasn't handled by www.example.com as PHP
// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
$foo = 1;
$bar = 2;
include 'file.txt'; // Works.
include 'file.php'; // Works.
This is what I tried to include
<?php include 'http://localhost/mysite/incl_layouts.blog/navigation.php';?>
HTTP is a protocol. It literally defines a way of encoding packets to send over the internet.
If you want to include a remote file, cut the HTTP from the front.
Why do you need to include a file by URL?
It's pretty rare where you would need to, or should use include on a url. Most of the time, readfile() is what you should use if the file is not on the local filesystem.
But anyway, you say it "doesnt work". How have you determined it doesn't work? What did you expect to happen? What actually happened?
so that i dont have to write this in one file
Originally Posted by sk89q
and then include the path like this in another file
my idea is to track down the absolute path, so that i dont have to change it so many times when it is located in different locations...
It wont work bcos the include content doens show on the screen...
Originally Posted by crmalibu
but i think i have found a solution...
result is this,
<?php echo $path = $_SERVER['DOCUMENT_ROOT'].'/mysite/incl_layouts.blog/navigation.php';?>