Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda