I'm trying to get the contents of a site hosted on a local server. Normally, I'd just do this: file_get_contents("https://www.sampleurl.com") Code (markup): Unfortuantely, the function is unable to open the file for security purposes. Since the file is local, my next choice was to try this method: file_get_contents("path/to/file.php") Code (markup): This time, the function doesn't work because I'm trying to get what the file would display rather than what the file actually contains. Imagine, for example, that file.php was this: require("header.html"); require("content.html"); require("footer.html"); Code (markup): I would only get the require statements using the file_get_contents function. Finally, I tried this method: echo "<div style='display:none'>"; require("path/to/file.php"); echo "</div>"; Code (markup): But this doesn't return the text; rather, it executes the text and prints the results. The only way I can think of to recover this data would be using JavaScript. It seems like there should be a compile a php file and store the text output in a variable, but for the life of me I can't figure it out. I'm open to any suggestions. Thanks!
Actually, for the third method you can use ob_start: ob_start(); require 'path/to/file.php'; $output = ob_get_contents(); PHP: As far as the first method, you may want to check if your host supports curl.. // create a new cURL resource $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); curl_close($ch); PHP:
The host doesn't support curl, but the ob_start() / ob_get_clear() method worked perfectly! I can't even express how much time and stress you just saved me. Thanks for your help!