Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2004, 05:29 PM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing a URL to fopen()

I'm new so forgive my stupidity. I'm trying to write a scraper program in PHP and I think one way is to use fopen() to get a URL.

Every time I try to feed it a web address I get the error message:

Warning: fopen(http://www.Whatever-I-Use.com/): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/virtual/site3/fst/var/www/html/scrape.php on line 10

It lets me get pages on my server but, anytime I try to go outside I get that error message. What's up? Anyone?

 
Old April 3rd, 2004, 08:32 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi,
    It'd help if you could post some code to go along with this.

    Have you made sure to open for read-only?
    $handle = fopen("http://www.example.com/", "r");

: )
Rich


::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 6th, 2004, 01:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you have a newer version of PHP, you can use file_get_contents instead, and not have to deal with getting a file handle and using fread() and fclose()

 http://www.php.net/file_get_contents

This should also work for HTTP URLs.


Take care,

Nik
http://www.bigaction.org/
 
Old April 6th, 2004, 01:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, check the value of "allow_url_fopen" in php.ini (you can check this in phpinfo() output).


Take care,

Nik
http://www.bigaction.org/
 
Old April 6th, 2004, 06:58 PM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks everyone, I'll try it all and tell you how it works out. Much appreciated.

Dadio






Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameter in URl alamoudi ASP.NET 1.x and 2.0 Application Design 0 May 2nd, 2007 02:10 AM
Passing parameters in URL british4 Crystal Reports 1 June 27th, 2005 02:55 AM
Passing URL in a Querystring [email protected] Javascript How-To 3 July 8th, 2004 04:59 PM
passing a variable through URL katie456 Classic ASP Databases 2 January 20th, 2004 11:27 PM
Passing URL data Brian_S Dreamweaver (all versions) 2 December 1st, 2003 08:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.