473,411 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

fsockopen(), fopen() and file()

I'm trying to write a script that will connect to an external site so
that I can get access referer information in a database on another one
of my sites. I got errors, so I tried to write a script that will test
the three main forms of connecting externally: fsockopen, fopen and
file.

I wrote a simple script that connects to my own domain
(http://www.kigurumi.co.uk) and to another external domain
(http://www.yahoo.co.uk), I do nothing other than connect.

This is the script:

<?
if(fsockopen("Kigurumi.co.uk", 80)) {
echo "Connect 1 OK";
}
else {
echo "Connect 1 Failed";
}

echo "\n";

if(fsockopen("yahoo.co.uk", 80)) {
echo "Connect 2 OK";
}
else {
echo "Connect 2 Failed";
}

echo "\n";

if (fopen("http://www.kigurumi.co.uk", "r")) {
echo "Connect 3 OK";
}
else {
echo "Connect 3 Failed";
}

echo "\n";

if (fopen("http://www.yahoo.co.uk", "r")) {
echo "Connect 4 OK";
}
else {
echo "Connect 4 Failed";
}

echo "\n";

if (file("http://www.kigurumi.co.uk")) {
echo "Connect 5 OK";
}
else {
echo "Connect 5 Failed";
}

echo "\n";

if (file("http://www.yahoo.co.uk")) {
echo "Connect 6 OK";
}
else {
echo "Connect 6 Failed";
}

echo "\n";
?>

When I run it, I get the following messages (for obvious security
reasons, I have hidden part of my directory):

Connect 1 OK
Warning: fsockopen(): unable to connect to yahoo.co.uk:80 in
[hidden]htdocs/test.php on line 11
Connect 2 Failed Connect 3 OK
Warning: fopen(http://www.yahoo.co.uk): failed to open stream:
Permission denied in [hihdden]htdocs/test.php on line 29
Connect 4 Failed Connect 5 OK
Warning: file(http://www.yahoo.co.uk): failed to open stream:
Permission denied in [hidden]htdocs/test.php on line 47
Connect 6 Failed

You can see that when I connect to my own domain (connects 1, 3 and 5),
it works fine, but whenever I connect to the external site, (connects
2, 4 and 6), it fails. It can't be to do with the argument format,
since I'm using the same format for both calls (e.g. "kigurumi.co.uk"
and "yahoo.co.uk" for example for fsockopen())

I have spoken to my ISP, and they have mentioned that they have
recently implemented a register_globals set to off policy, but this
doesn't affect my code, since I'm not using any variables, especially
global ones. They are not really helping me very much, much as I hate
to say it.

If I run this script on my own machine (WinXP, SP2, php 4.2.1,
register_globals off) using:

c:\php\php.exe test.php

I get Connect 1 OK through to Connect 6 OK, so there's obviously a
difference in configuration, but _what_?

Does anyone know why this is happening, or what I can do to allow
myself to connect to external machines.

Regards

Loopy

Jul 17 '05 #1
2 4035
"Loopy" <jj****@yahoo.com> wrote in news:1110360731.972876.295620
@g14g2000cwa.googlegroups.com:
I get Connect 1 OK through to Connect 6 OK, so there's obviously a
difference in configuration, but _what_?

Does anyone know why this is happening, or what I can do to allow
myself to connect to external machines.


Regarding the fopen() and file() calls, it sounds like your host has
allow_url_fopen turned off. This doesn't explain fsockopen() failing,
though. The errors you're getting are not consistent with a safe mode
installation, either, so it's difficult to pinpoint one cause.

Is Kigurumi.co.uk hosted on the same machine you're running the script
on? If so, try a test subject other than Yahoo, like Google or BBC, and
see if it can connect to them. This will either show that Yahoo is
blocking your server, or that your server is blocking outbound
connections. If the latter, ask your host if they have a firewall
preventing egress on port 80.

You're correct in that register_globals would have nothing to do with
this.

hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Jul 17 '05 #2
Thanks for the information about that. I've forwarded it to my ISP and
I'll see what they say. They have tried to help me on numerous
occasions, but they keep saying it's to do with register_globals --
which it isn't, as you've just confirmed. I'm going to send them the
Google Groups URL and let them read this. :)
Loopy

Jul 17 '05 #3

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

Similar topics

3
by: Michael T. Peterson | last post by:
I am trying to get the file referenced by the following url: http://waterdata.usgs.gov/wa/nwis/uv?dd_cd=01&dd_cd=02&format=rdb&period=1&site_no=12149000 I'm using parse_url to get the host,...
1
by: Nima | last post by:
Hi all, I'm trying to open, read and extract information from a website (maximum and minimum temps from http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV10450.txt )... Could anyone give me some...
5
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...
1
by: Gil-Dale | last post by:
Trying to make a connection via a proxy to another site using the fsockopen I can get it hitting the proxy server just can't get it through. I have user name and password to get through the...
13
by: lkrubner | last post by:
Suppose I need to get an image as a stream of bytes. I want to store this in a variable and then embed it in some Postscript code. In my Postscript code, the image might look like this: {<...
8
by: Yoko | last post by:
So I am using php version 4.3.9 and lets say i have a file on the server called tester.php so i am using fsockopen to point to that file but it gives me a error below. $fh =...
4
by: keychain | last post by:
I'm experience the infamous "SSL: Fatal Protocol Error" bug with Apache 2.x According the fopen() documentation: "If you are using fsockopen() to create an ssl:// socket, you are responsible...
8
RedSon
by: RedSon | last post by:
Dang this free hosting site. They made it so I can't use fsockopen, which normally I wouldn't care about but I want to be able to use some anti spam type software like captcha and akismet. They said...
3
by: jeddiki | last post by:
Out of these, which one do you use most and why ? fsockopen, curl, fopen, file_get_contents,
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.