Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda