Jump to content

[SOLVED] file_get_contents 404 error.


Normac

Recommended Posts

Right got the post wrote down now :D

 

main.php:

include ('function.php');
$linkss=file(something.txt');
foreach ($linkss as $line_num => $link) {
$pieces = explode('/', $link);
linkgetter($link, "links.txt", "");

 

something.txt format:

http://www.example.com/page/1.html
http://www.example.com/page/2.html
http://www.example.com/page/3.html

 

Important linkgetter code:

function linkgetter($url, $filename, $testinternal)
{
$fh=fopen('something.txt', 'w') or die();
$output = file_get_contents($url, "r"); 
//do stuff with output
$cat="$cat\n";
}

All that Function.php just includes the linkgetter function. The linkgetter function just gets some links (I'm tracking backlinks and checking if they still work) and prints some info.

 

Now I'm using PHP 4 on a  local sever, though the websites are online. Every loop I get the following error message.

 

Warning: file_get_contents(http://www.example.com/page/1.html ) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\scraper\function.php on line 7

 

If i replace $url with $output = file_get_contents(http://www.example.com/page/1.html, "r"); it works. (The Page exists.)

 

So what am I doing wrong?

Link to comment
Share on other sites

You're missing an opening quote.

 

$linkss=file(something.txt');

 

should be

 

$linkss=file('something.txt');

 

Yea I changed the filename for viewing here, accedently deleted a ' .

 

If i replace $url with $output = file_get_contents(http://www.example.com/page/1.html, "r"); it works.

 

I don't see where you use $url in your code. Anyway, are url_wrappers enabled?

 

It is there:

 

function linkgetter([b]$url[/b], $filename, $testinternal)
{
$fh=fopen('something.txt', 'w') or die();
$output = file_get_contents([b]$url[/b], "r"); 
//do stuff with output
$cat="$cat\n";
}

$linkss=file(something.txt');
foreach ($linkss as $line_num => $link) {
$pieces = explode('/', $link);
linkgetter([b]$link[/b], "links.txt", "");

 

Basicly it takes lists of links from a txt file, then takes the pages to check for certain info.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.