0

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 https://i.stack.imgur.com/VM09P.png

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

Zeus
  • 1,235
  • 12
  • 20
  • 4
    `The URL http://thepilotslife.com/assets/chat-output.php opens well in borwser, try opening yourself, ` Just tried and got a 500 :) Incorrect claim – Hanky Panky Feb 05 '15 at 12:41
  • `500 Internal Server Error - http://thepilotslife.com/assets/chat-output.php"` in Firefox. – DeDee Feb 05 '15 at 12:45
  • Works fine for me I just tried opening it 20 sec ago works fine here is a pic for your reference http://i62.tinypic.com/k1un8h.png – Zeus Feb 05 '15 at 12:46
  • The reason you're getting an error 500 is the same reason we're getting error 500's. There's something funky going on in their code. If this is your site (pilotslife) then look in your webserver logs. If it's someone elses code then tell them to fix it. – h2ooooooo Feb 05 '15 at 12:56
  • The code at link is not mine.. but the link works absolutely fine for me, I tired using a proxy and then it gave 500 error.. but works fine without proxy for me and works fine for other regular user of the site too – Zeus Feb 05 '15 at 12:59
  • Guys see edit part 2 maybe I added some useful information – Zeus Feb 05 '15 at 13:16
  • @Zeus My guess is that you have some cookies or a session set that no other person (or proxy, or script) has set, because they didn't access the site through the regular method. What happens is that it (*probably*) tries to read your session data, username or whatever, and fails since all us other people don't have any. Are you perhaps logged in? – h2ooooooo Feb 05 '15 at 13:19
  • @h2ooooooo ah yes, I just deleted all cookies from browser after seeing your reply and then tried to go to page didn't worked. Then I logged into my account and then tried and VOILA it worked, so I need to have the cookies which I get when I log in to access that page. So how will I do that, my guess is using cURL but how will I get cookies using cURL and then store it in my script so that I can access that page, a little example of it would be appreciated :) – Zeus Feb 05 '15 at 13:28
  • cURL can store cookies using a so called "cookie jar". It will automatically keep cookies sent from the server, so if you also implement login into your cURL script, then it should work. – h2ooooooo Feb 05 '15 at 13:29
  • That would solve my problem, Would have marked that as an answer if you have posted it as a answer but nevertheless thanks. – Zeus Feb 05 '15 at 13:41
  • @Zeus You're more than welcome to post an answer yourself once you've figured out the complete code in order to help others with the same sort of issue. :-) – h2ooooooo Feb 05 '15 at 13:44
  • possible duplicate of [Why I'm getting 500 error when using file\_get\_contents(), but works in a browser?](http://stackoverflow.com/questions/10524748/why-im-getting-500-error-when-using-file-get-contents-but-works-in-a-browser) – kenorb Mar 16 '15 at 17:43

1 Answers1

0

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
Zeus
  • 1,235
  • 12
  • 20