file_get_contents method doesn’t work if the file contains include coomand

I have a wordpress project. I tried to get the written content of php file with the file_get_contents, but it has got a problem, because the getting file has an include command, and this do the warning…

I have to use the file_get_contents() method, because I use an other online API, which work with this method!

Read More

In my file I use this file_get_contents() in the service.php:

$url = "http://localhost/davetips/sms_service.php";
$content = file_get_contents($url);
var_dump($content);
die();

And here the beginning of content of the “http://localhost/davetips/sms_service.php“:

<?php
// WordPress
global $wpdb;
include 'wp-blog-header.php';
echo "test";

error_reporting(E_ALL);
ini_set("display_errors", 1);

// Password constans
$option_password_text_key = 'password_storer_text';
// And more code ...

This php file didn’t throw any warning or error, if it is run in directly from the url.
It write out the “test” message in the browser.

If I wanna get this file by file_get_contents() from the first file. I get this problem:

Warning: file_get_contents(`http://localhost/davetips/sms_service.php`): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /var/www/wp-tutorial/service.php

If I comment out the include command, it will be ok!

So I don’t know, how I should include the wp-blog-header.php in the sms_service.php…

Does anyone has got a good advise?

Related posts

Leave a Reply