简体   繁体   中英

php - HTTP/1.1 500 Internal Server Error on file_get_contents

So as the title says I get - HTTP/1.1 500 Internal Server Error on file_get_contents Here is error log -

 ! ) Warning: file_get_contents(http://thepilotslife.com/assets/chat-output.php): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\wamp\www\test\index.php on line 3

The URL http://thepilotslife.com/assets/chat-output.php opens well in borwser, try opening yourself, try reloading the URL in browser every 5 sec you will not that the out put is diffrent every time, so I basically need to fetch data from that URL and then perform certain task on it. This is the php file content -

<?php
$baseurl = "http://thepilotslife.com/assets/chat-output.php";
$response = file_get_contents($baseurl);
echo $response;
?>

I tried using CURL too in the following manner

<?
$url = "http://thepilotslife.com/assets/chat-output.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>

The above CURL code do not give any error but it only gives me a blank page every time.. I used var_dump in CURL code too it showed that string is empty every time. I also googled and tried other solution but none worked.

EDIT : For some people the link is giving error even on browser but working fine for me so here is pic of link for reference http://i.stack.imgur.com/VM09P.png

Also note that file_get_contents and CURL are working perfectly with other links

Totally forgot to post solution of this. the problem was that, that page needed a php session id stored in form of cookie to work. Anyways this is how I solved my problem:

$ch = curl_init();//initialize the curl
curl_setopt($ch, CURLOPT_URL, 'https://thepilotslife.com/chat');//this page sets cookie
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//to overcome SSL verification
curl_exec($ch);//execute the curl to get and set cookies
curl_setopt($ch, CURLOPT_URL, 'https://thepilotslife.com/assets/chat-output.php');//now set the url to page which we needed the output from
echo curl_exec($ch);//echo the result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM