Forum Moderators: coopster

Message Too Old, No Replies

fsockopen

read a subdirectory

         

ikbenhet1

4:41 pm on Jun 5, 2003 (gmt 0)

10+ Year Member



The code below reads the source of www.example.com correct.
When i change $current_url to "www.example.com/examples/", i get an error message.
How can i read a subdirectory with fsockopen?


$current_url="www.example.com";
$fp = fsockopen ($current_url, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\nHost: ".$current_url."\r\n\r\n");
while (!feof($fp)) {
$current_url_content.=fgets ($fp,128);
}
fclose ($fp);
}

(works ok, until i specify a subdirectory. the error message)
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known

Warning: fsockopen() [function.fsockopen]: unable to connect to (snip) No such file or directory (2)

bcolflesh

4:50 pm on Jun 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does the subdirectory have an index file?

Regards,
Brent

ikbenhet1

4:57 pm on Jun 5, 2003 (gmt 0)

10+ Year Member



Yes, the subdirectory contains index.php.

I just i also tried "www.example.com/example/index.php" and i get the same message.

I was still trying and already changed a bit of the code, i will post it again sorry.


$current_url="www.example.com";
$current_dir="www.example.com/sub/index.php";
$fp = fsockopen ($current_dir, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\nHost: ".$current_url."\r\n\r\n");
while (!feof($fp)) {
$current_url_content.=fgets ($fp,128);
}
fclose ($fp);
}

(of course example.com is not the domain i'm trying to acces, i replaced my url with that)

bcolflesh

5:02 pm on Jun 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ignore my previous question - just read the man page. Fsockopen just opens a socket request (imagine that!) - you would have to send a GET or POST command in the header to interact with files in subdirectories.

Regards,
Brent

SEO practioner

5:03 pm on Jun 5, 2003 (gmt 0)

10+ Year Member



Let me look in my notes here... brb

Xuefer

5:11 pm on Jun 5, 2003 (gmt 0)

10+ Year Member



did u read php manual?
int fsockopen ( string hostname, int port [, int errno [, string errstr [, float timeout]]])

it should be hostname, not URL not DIR

url should be present in HTTP Protocol request headers
GET /sub/index.php HTTP/1.0
Host: www.example.com

hrm... do u know the differences between hostname/url/directory :P

ikbenhet1

5:13 pm on Jun 5, 2003 (gmt 0)

10+ Year Member



Seopracticer, stop looking please.
php manual indeed shows an example.
Thank u for getting me on my path again.