Fopen not working?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hauni
Forum Newbie
Posts: 11
Joined: Thu Sep 25, 2008 11:40 am

Fopen not working?

Post 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!
niallsc
Forum Newbie
Posts: 7
Joined: Thu Jun 10, 2010 1:09 pm

Re: Fopen not working?

Post 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.
hauni
Forum Newbie
Posts: 11
Joined: Thu Sep 25, 2008 11:40 am

Re: Fopen not working?

Post by hauni »

I tried now, but I still get the same errors. Same with curl btw.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Fopen not working?

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
hauni
Forum Newbie
Posts: 11
Joined: Thu Sep 25, 2008 11:40 am

Re: Fopen not working?

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Fopen not working?

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
hauni
Forum Newbie
Posts: 11
Joined: Thu Sep 25, 2008 11:40 am

Re: Fopen not working?

Post 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/.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Fopen not working?

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
hauni
Forum Newbie
Posts: 11
Joined: Thu Sep 25, 2008 11:40 am

Re: Fopen not working?

Post by hauni »

Sigh... Why can't things be straightforward? :cry:

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