1

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!

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?

6
  • Are you sure allow_url_fopen is enabled?
    – Ohgodwhy
    Dec 25, 2013 at 22:59
  • Yes, it is on in the PHP ini file :) allow_url_fopen = On Dec 25, 2013 at 23:19
  • The warning has nothing to do with the file_get_contents, Are you sure that localhost/davetips/sms_service.php does exists? according to the warning message you posted it means that the requested file is not found. Dec 25, 2013 at 23:26
  • Hey, :) It exists. This file_get_contents() method works, If I comment out the include command in the getting php file!!! So the file exists! (So, If I comment out the include command, It will find this file ;) ) Dec 25, 2013 at 23:30
  • Have you checked your server logs? Does going to http://localhost/davetips/sms_service.php via the browser give an error? Does wp-blog-header.php exist in the same directory as sms_service.php or the php include path?
    – towr
    Dec 26, 2013 at 15:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy