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