Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
file_get_contents outputs bad request PHP

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

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!