0

My local Windows 10 Apache2.4 and PHP 7 server has a file with the following code ( output.php )

<?php

    file_get_contents("https://www.MY-WEB-ADDRESS.com/dir/index.php");

?>

My remote server MY-WEB-ADDRESS has a file at /dir/index.php with the following code

<?php

    include $_SERVER['DOCUMENT_ROOT'].'/res/databin/key.php';

    if ( isset($_GET['sid']) ){

        $sid = $_GET['sid'];
        $query = "SELECT * FROM data WHERE data_id = '$sid'";
        $result = mysqli_query($mydb, $query);

        if ( $result && mysqli_num_rows($result) > 0 ){
            $row = mysqli_fetch_assoc($result);
            echo $row['data_id'];
        }
        else{
            echo "-1";
        }
    }
    else{
        echo "-1";
    }

?>

I have checked the local and remote servers PHP.ini to ensure allow_url_fopen is enabled. I've restarted my local webserver and also ensured that my HTTPS wrapper is enabled. I always get the following message

Warning: file_get_contents(h ttps://www.MY-WEB-ADDRESS.com/dir/index.php): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\Apache24\htdocs\dir\output.php

As I'm not passing the "sid" argument I would expect to receive a -1 but all I get is the output error above. What else can I check to make this work? The data is supposed to output in nothing but plain text with no formatting.

EDIT I have also tried calling file_get_contents without using HTTPS

  • This `https://www.MY-WEB-ADDRESS.com/dir/index.php` in a browser works? – AbraCadaver Apr 10 '20 at 18:02
  • @AbraCadaver Yes. It's my company's website. Furthermore I can actually get the correct data if I pass the URL into an iframe. I should note that I did mask the actual URL with "MY-WEB-ADDRESS" due to privacy – theraveboss Apr 10 '20 at 18:04
  • The error shows a space `h ttps` is that really in the error or accidental edit? – AbraCadaver Apr 10 '20 at 18:06
  • @AbraCadaver I added that so that the page here wouldn't show that as a clickable link due to my above comment about masking. – theraveboss Apr 10 '20 at 18:06
  • Take a look at: [file_get_contents throws 400 Bad Request error PHP](https://stackoverflow.com/questions/8482782/file-get-contents-throws-400-bad-request-error-php) – EternalHour Apr 10 '20 at 18:15
  • @EternalHour I had read through that before posting. "Just use curl" doesn't really answer this particular question though. There is good information there but unless I missed something I don't believe it pertains. – theraveboss Apr 10 '20 at 18:20
  • It says to use curl so you can determine what the problem is, not a permanent solution. – EternalHour Apr 10 '20 at 18:21
  • @EternalHour When I try to use the example provided for cURL I get the following error Call to undefined function curl_init() I checked and it is indeed enabled on my server. – theraveboss Apr 10 '20 at 18:24
  • Based on that error it would appear it's not. – EternalHour Apr 10 '20 at 18:26
  • @EternalHour I'm going to try reinstalling PHP because it definitely displays that it's enabled. Reinstall is the only thing I can think of at this point. – theraveboss Apr 10 '20 at 18:29
  • May be related to the HTTP 400. You could try reinstalling that module only. – EternalHour Apr 10 '20 at 18:45

0 Answers0