I’m facing a problem with the include function when the included file is having a header code…
I use in my file1.php this simple code
include "http://localhost/test/file2.php";
and the file2.php have this code
header("HTTP/1.0 404 Not Found");
include "http://localhost/test/error404.html";
and when i call file1.php it gets me this error
Warning: include(http://localhost/test/file2.php) [function.include]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\\xampp\\htdocs\ est\\file1.php on line 3
Warning: include() [function.include]: Failed opening 'http://localhost/test/file2.php' for inclusion (include_path='.;C:\\xampp\\php\\PEAR') in C:\\xampp\\htdocs\ est\\file1.php on line 3
when i remove the header function [header(“HTTP/1.0 404 Not Found”);] from file2.php and the code is like
include "http://localhost/test/error404.html";
it includes the error404.html page normally
is there any way to keep the header code cuz I’m gonna need it in the RSS file as it must contain the code
header('Content-Type: text/xml');
notice that the “allow_url_fopen” and “allow_url_include” functions are switched on
Include them using RELATIVE uri’s, not absolute.
Using the absolute (http://…) means that PHP will make an external connection rather than a local file read. Local file read = I get the source code. External connection = I get the RESULT. Your result = 404 status, hence the error.
so if i used the include function to include a local file the category will include it like “http://localhost/test/cat/error404.html” which is not on the server
so is there any other way ? or should i try to solve the second problem ?
thank you and that’s what i’ve said above
notice that the “allow_url_fopen” and “allow_url_include” functions are switched on
I’m… fairly sure category.php still recognizes that it’s in the test directory. And your 404 file is in the test directory. so… “include(‘error404.php’);” should work. (if not, it’s include(‘…/error404.php’) instead). They’re still on the same server. Directory != server.
and it’s working but the problem when i include file like “file2.php?id=12”
it gives me this error
Warning: include(file2.php?id=12) [function.include]: failed to open stream: No error in C:\\xampp\\htdocs\ est\\file1.php on line 5
Warning: include() [function.include]: Failed opening 'file2.php?id=12' for inclusion (include_path='.;C:\\xampp\\php\\PEAR') in C:\\xampp\\htdocs\ est\\file1.php on line 5
<?php
/* This example assumes that www.example.com is configured to parse .php
* files and not .txt files. Also, 'Works' here means that the variables
* $foo and $bar are available within the included file. */
// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';
// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';
// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';
$foo = 1;
$bar = 2;
include 'file.txt'; // Works.
include 'file.php'; // Works.
?>
Ohh haha, I made this mistake once of thinking I found a huge hole. The .php page of a website downloaded instead of loading. I thought it would’ve been all of the code in the page when I opened it but it was already formatted into html.