Ask a question about fopensocket. This post was last edited by php_aga from 2014-07-0415: 42: 52 in the local WAPM environment, php. enable allow_url_fopen & nbsp; Onwrite. php & lt ;? Php & nbsp; $ fp & nbsp; fso ask a question about fopensocket
This post was last edited by php_aga at 15:42:52 on February 4 ,.
In the local WAPM environment, php. ini has opened allow_url_fopen = On.
Write. php
$ Fp = fsockopen ('localhost', 80, & $ errno, & $ errstr, 5 );
If (! $ Fp)
{
Echo "$ errstr ($ errno)
\ N ";
}
Else
{
Fputs ($ fp, "GET/HTTP/1.0 \ nHost: http: // localhost/1.php ");
Fclose ($ fp );
}
?>
1.php exists in the localhost root directory, but after the test runs write. php,
It is found that 1. php is not executed, and 1. php can be run separately.
Why?
I tried to change http: // localhsot/1. php to 1. php. I cannot create a link.
------ Solution --------------------
$fp = fsockopen('localhost', 80, $errno, $errstr, 5);
if(!$fp) {
echo "$errstr ($errno)
\n";
}else {
fputs($fp,"GET /1.php HTTP/1.0\r\nHost: localhost\r\nConnection: Close\r\n\r\n");
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}