Page 1 of 1

Fopen not working?

Posted: Tue Jun 15, 2010 11:31 am
by hauni
Alright, so the deal is, I want to read the contents of this page:
http://www.skrivebua.no/index.html?skri ... bnr=581780

And here goes my code:

Code: Select all

$fp1 = fopen("http://www.skrivebua.no/index.html?skrivebua.cgi?a=lesbidrag&bnr=581780", "r");
while (feof($fp1) != 1)
$text= $text.stripslashes(fgets($fp1,10000)); str_replace("+", " ", $text);
echo $text;
I get this error:
[text]
Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

Object not found!

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404
localhost
15.06.2010 18:25:13
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 [/text]

The weird thing is, if I use the code on another website, for instance http://www.tibia.com, the site gets displated perfectly. What am I doing wrong?

Thanks in advance!

Re: Fopen not working?

Posted: Tue Jun 15, 2010 11:44 am
by niallsc
have you tried using file_get_contents($filename); ?
I ran into this same problem and when I used file_get_contents() it worked all the time.

Re: Fopen not working?

Posted: Tue Jun 15, 2010 11:56 am
by hauni
I tried now, but I still get the same errors. Same with curl btw.

Re: Fopen not working?

Posted: Tue Jun 15, 2010 12:07 pm
by AbraCadaver
hauni wrote:I tried now, but I still get the same errors. Same with curl btw.
Look at the source of the page. The page is loading, but it is a frameset and it is trying to load pages into the frames using relative paths. Since those pages are not found on your server it displays a not found.

Re: Fopen not working?

Posted: Tue Jun 15, 2010 12:09 pm
by hauni
AbraCadaver wrote:
hauni wrote:I tried now, but I still get the same errors. Same with curl btw.
Look at the source of the page. The page is loading, but it is a frameset and it is trying to load pages into the frames using relative paths. Since those pages are not found on your server it displays a not found.
Yeah, I saw that.
Uhm, but somehow I need to acquire the information. Do you have any suggestions of what I can do?

Re: Fopen not working?

Posted: Tue Jun 15, 2010 12:26 pm
by AbraCadaver
Use the base tag, that's what it's for:

Code: Select all

$text = file_get_contents('http://www.skrivebua.no/index.html?skrivebua.cgi?a=lesbidrag&bnr=581780');
$text = str_ireplace('</head>', '<base href="http://www.skrivebua.no/"></head>', $text);

Re: Fopen not working?

Posted: Tue Jun 15, 2010 12:34 pm
by hauni
Thanks.
But the thing is, when I do this only the front page of the website will be displayed.
Meaning when I echo it, I don't get this site: http://www.skrivebua.no/index.html?skri ... bnr=581780, as I desire, rather I get the front page, http://www.skrivebua.no/.

Re: Fopen not working?

Posted: Tue Jun 15, 2010 1:03 pm
by AbraCadaver
hauni wrote:Thanks.
But the thing is, when I do this only the front page of the website will be displayed.
Meaning when I echo it, I don't get this site: http://www.skrivebua.no/index.html?skri ... bnr=581780, as I desire, rather I get the front page, http://www.skrivebua.no/.
Because the page has some javascript that looks at the URL in the browser (your site) and determines what to load based upon that. You'll need to work out what it needs and make your page URL contain those things.

Re: Fopen not working?

Posted: Tue Jun 15, 2010 1:16 pm
by hauni
Sigh... Why can't things be straightforward? :cry:

Thanks for your help, even though I believe I hit my barrier.