html - How to open a local file/url and include its output into another page via PHPGet the solution ↓↓↓
Hello I have a one page website (the entire site is in one page):
I want to wrap the header and footer of that page around another page inside a folder on the server:
(with headers and footer of /index.html, but different content)
I've isolated the header and footer and saved them in separate files in the root:
If launched from the root they display correctly but I can't seem to include them in the "newpage.php" because none of the CSS, JS and images inside the header and footer are loaded.
I've tried the following 4 methods:
include($_SERVER["DOCUMENT_ROOT"].'/index_header.html'); file_get_contents($_SERVER["DOCUMENT_ROOT"].'/index_header.html'); ob_start(); include($_SERVER["DOCUMENT_ROOT"].'/index_header.html'); $output = ob_get_clean(); echo $output; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://".$_SERVER['HTTP_HOST']."/index_header.html"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); echo $output; curl_close($ch);
But none of these methods work... Can anyone help me out? Thank you
I've ended up changing all the JS, image and CSS calls to absolute urls starting from the root which allowed me to use include() Thank you
People are also looking for solutions of the problem: foreach() argument must be of type array|object, null given
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.