Jump to content

Archived

This topic is now archived and is closed to further replies.

Warz

[SOLVED] file_get_contents 404

Recommended Posts

Hi,

 

I am been using this command for a while: file_get_contents('http://domain.com');

 

However, recently domain.com changed servers and I'm now recieving following error:

failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/warzfile/public_html/customscripts/file_get_contents_test.php on line 249

 

I do have access to the server I'm trying to "fetch" from. I can also mention that some pages works, while this one don't. It just doesn't make any sense to me  :-[

 

Whats this error? How can I fix this?

 

Thanks!

Share this post


Link to post
Share on other sites

No, I am the owner of both servers and I can access that page with no problem by entering it in firefox....

Share this post


Link to post
Share on other sites

Need more info.. ie the url your trying, best guess is your URL is incorrect, (check for spaces)

Share this post


Link to post
Share on other sites

This is my code:

$strURL = 'http://dcl.vg.to/fetchme.php?id=11602';
$strContent = file_get_contents($strURL);
echo $strContent;

 

And I get this error

Warning: file_get_contents(http://dcl.vg.to/fetchme.php?id=11602) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/warzfile/public_html/customscripts/file_get_contents_test.php on line 251

 

If you try that url you will see that it works, but not when fetching??

Share this post


Link to post
Share on other sites

That's strange... any idea why it doesn't work for me?  :confused:

Share this post


Link to post
Share on other sites

what version of IE?

any manuipulation with the url? not encoded special chars?

Share this post


Link to post
Share on other sites

What does this have to do with IE? IE as in Internet Explorer? or...?  Since it's working for MadTechie I assume it must be some sort of server error?

 

Also donno what you mean by manuipulation of url... I'm just using the url http://dcl.vg.to/fetchme.php?id=11602

Share this post


Link to post
Share on other sites

Well, because a browser interpretation of code and url interpretation can differ alot from a version to an other.

is it external hosting? (I believe so but still asking)

Share this post


Link to post
Share on other sites

Well the server your connecting to seams okay, as the connection is valid

Date: Wed, 07 Oct 2009 14:53:12 GMT

Server: Apache/2.2.3 (Red Hat)

X-Powered-By: PHP/5.1.6

Content-Length: 313

Connection: close

Content-Type: text/html; charset=UTF-8

 

200 OK

 

the server your running dvdcoverlinks.com on did it used to work and have you changed anything as i would suggest checking that allow_url_fopen is enabled in PHP.INI configuration file.

allow_url_fopen = On

 

also try another URL see if its any URL or just that one

Share this post


Link to post
Share on other sites

Well the server your connecting to seams okay, as the connection is valid

Date: Wed, 07 Oct 2009 14:53:12 GMT

Server: Apache/2.2.3 (Red Hat)

X-Powered-By: PHP/5.1.6

Content-Length: 313

Connection: close

Content-Type: text/html; charset=UTF-8

 

200 OK

 

the server your running dvdcoverlinks.com on did it used to work and have you changed anything as i would suggest checking that allow_url_fopen is enabled in PHP.INI configuration file.

allow_url_fopen = On

 

also try another URL see if its any URL or just that one

Yes allow url fopen is on. Other URLs work. Well, not really all of them...

 

The reason I made this file in the first place was because :

http://dcl.vg.to/details.php?image_id=11602 <--- works, can be fetched

http://dcl.vg.to/details.php?image_id=11605 <--- does NOT work, cannot be fetched

 

When I enter http://dcl.vg.to/details.php?image_id=11605 it fetched http://dcl.vg.to instead!

 

Isn't that strange? Those pages are completely identical (except from a few different values), yet when I try to fetch the 11605 one I'm redirected to main page? Doesn't make any sense at all  :confused:

 

That's why I made this new file, to see if I could figure out what was wrong, and then I'm getting that error...  :confused:

Share this post


Link to post
Share on other sites

You might want to check the web server access log and error log on the remote system to see what kind of entries there are that correspond to the http requests being made to it.

 

Are you doing any URL rewriting or checking of thing like HTTP_REFERER on the remote system that would cause the remote server to return a http 404 response code for what you are requesting?

 

Have you recently changed any of your web hosting or moved your domain registration to a new registrar? This almost sounds like a DNS issue where the request is actually going to the wrong server because an old cached DNS entry is being used some of the time or every time.

Share this post


Link to post
Share on other sites

This almost sounds like a DNS issue where the request is actually going to the wrong server because an old cached DNS entry is being used some of the time or every time.

I was thinking the same thing!

 

 

just wondering.., try this (may give some insight)

<?php
$strURL = 'http://dcl.vg.to/fetchme.php?id=11602';
$ch = curl_init($strURL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$strContent= curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
//$strContent = file_get_contents($strURL);
echo $strContent;
echo "<br /><br />DEBUG\n<pre>";
var_dump($info);
echo "</pre>";
?>

Share this post


Link to post
Share on other sites

OMG OMG!.... How can I forget something like that  :facewall: :facewall: :facewall: :facewall:

Thank you! yes it must have been DNS issue... I had forgotten to remove the dns records from my old server  ::)

 

Now there is a new error displaying instead:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/dvdcover/public_html/customscripts/file_get_contents_test.php on line 4

 

Warning: file_get_contents(http://dcl.vg.to/fetchme.php?id=11602) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/dvdcover/public_html/customscripts/file_get_contents_test.php on line 4

Share this post


Link to post
Share on other sites

Here is result from your script:

DEBUG

 

array(20) {

  ["url"]=>

  string(37) "http://dcl.vg.to/fetchme.php?id=11602"

  ["content_type"]=>

  NULL

  ["http_code"]=>

  int(0)

  ["header_size"]=>

  int(0)

  ["request_size"]=>

  int(0)

  ["filetime"]=>

  int(-1)

  ["ssl_verify_result"]=>

  int(0)

  ["redirect_count"]=>

  int(0)

  ["total_time"]=>

  float(0)

  ["namelookup_time"]=>

  float(0)

  ["connect_time"]=>

  float(0)

  ["pretransfer_time"]=>

  float(0)

  ["size_upload"]=>

  float(0)

  ["size_download"]=>

  float(0)

  ["speed_download"]=>

  float(0)

  ["speed_upload"]=>

  float(0)

  ["download_content_length"]=>

  float(-1)

  ["upload_content_length"]=>

  float(-1)

  ["starttransfer_time"]=>

  float(0)

  ["redirect_time"]=>

  float(0)

}

 

Share this post


Link to post
Share on other sites

Basic result is server host not found.. try pinging server from PHP server (check IP returned if any), check 'A Record's / Name server

Share this post


Link to post
Share on other sites

remove the dns records from my old server

It sounds like the domain name record at your domain registrar is still pointing to the name server for the old server as well.

 

With the DNS zone records still present, the IP address was resolving to an actual web server, the old server, and it actually received the http request, but the requested content was not present, giving the 404 response. When you removed the DNS zone records, the IP address is no longer resolving to any web server.

Share this post


Link to post
Share on other sites

But if you look at the curl http_code is 0 and NOT 404 as expected so I say domain not found at all!

Share this post


Link to post
Share on other sites

Thanks a lot guys! I had to delete even som more records, like the nameservers. It seems to be working fine now  :happy-04::thumb-up::happy-04: :happy-04: Thanks!

Share this post


Link to post
Share on other sites

Just one thing remaining then..

clicking of the topic solved button (bottom left)

:D

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.