473,811 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fopen() unable to open some URLs?

Hi,

I've used fopen() extensively to open web pages. I've found that there is a
small minority
of web pages that open fine in a browser, but are inaccessible using
fopen(). Here are
two such URLs:

http://www.homes.com/
http://www.dolbyproperties.com/

For example, using the code below, almost every web page that will open in a
browser
will be read correctly by this code. There are few exceptions, such as the
above URLs.
I'm wondering why/how could a page be accessible to a browser but not to
fopen()?

Here's the code:

<?php

$page = "";

if (isset($url))
{
$fp = fopen($url, 'r');

if ($fp != false)
{
while (feof($fp) == false)
{
$page .= fread($fp, 10000);
}

fclose($fp);

echo "URL: $url =============== =============== =======<br><br> ";
echo $page;
}
}

?>

I have this code running with a simple form interface here:

http://linkmachine.net/fopen_test.php

Any ideas?

Thank you,

-Michael


Aug 11 '05 #1
1 2377
Michael Ferrier wrote:
For example, using the code below, almost every web page that will
open in a browser
will be read correctly by this code. There are few exceptions, such
as the above URLs.
I'm wondering why/how could a page be accessible to a browser but not
to fopen()?


Some websites require an explicit user-agent header in order to return a
response, as is the case with homes.com

There are several ways to include the user agent, of which the easiest is to
apply the ini_set function as follows:

ini_set('user_a gent','Mozilla' );
$fp = fopen('http://www.homes.com/','r');
fpassthru($fp);

When you run this code, you will see it works fine for homes.com. Bare in
mind that this doesn't work for sites which require more then a user agent
string to operate.

JW

Aug 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2975
by: Shaoyong Wang | last post by:
Dear All, I want to write a simple PHP code to verify whether a given list of URLs is broken or not. The URLs given have various formats, for example, http://www.afro.com/history/history.html http://www.worldhistorycompass.com/index.htm http://www.afup.org/article.php3?id_article=242 fsockopen(...) only accepts target format (like www.yahoo.com etc), so I
3
3694
by: Ming | last post by:
When I use fopen on the URL: fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r") I would get the following error message: -----------Error Message------------ Warning: fopen(): Circular redirect, aborting. Warning: fopen(http://home.pchome.com.tw/world/qoo4ko/110.jpg): failed to open stream: Permission denied ------------------------------------
10
1934
by: Longfellow | last post by:
Newbie here... My reading of the description of fopen() led me to expect that, with mode as "w", it would create a file if it did not exist. Checked the FAQ and did not see this question addressed. What don't I understand? Thanks, Longfellow
5
7487
by: eyalc1978 | last post by:
Hi Does someone knows if fopen() is a non-blocking function in a sense that if there isn't sufficient disk space to open a file in write mode, then the function will not wait but fail? I find it difficult to believe that anyone who use this function wants the program to wait until disk space is enlarged
4
2880
by: lucyachammond | last post by:
I have a 3rd party real-estate website written in php. I would like to call an asp script on a separate webserver each time a new real-estate item is added to the database on the php site. The asp script updates a sql server database for another site and once the page has been called, I do not need any return information from it. I have searched the groups but cannot find a definitive way of making the call to the asp script - I am a...
1
5559
by: nebelraabe | last post by:
hi there. I encountered a problem when i wanted to open a file which name i read from an ini file. FILE *fopen(const char *filename, const char *mode); as far as i know, fopen( ) accepts only constants as parameters. that's my code: FILE *fp;
25
3375
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
3
17222
by: mrmattborja | last post by:
Hello, Here is a program I'm playing around with for fun in the process of learning C. The objective is to create a function filesize() and call it from within the main() section to retrieve the size in bytes of a file that I give it. #include <stdio.h> long filesize(f) { FILE *fp;
6
1997
by: chazzy69 | last post by:
So the function fopen() works most of the time heres the line im using- $file = fopen($nextPage, "r") or exit("Unable to open file!"); But for some reason that i haven't been able to discern yet im getting "Unable to open file!" on specific urls this wouldn't be so much of a problem but it ends up hanging the rest of the program up. Anyway so far i cant see any reason for the errors to occur becuase when theres a error i...
0
9726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10384
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10395
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.