Ask a question about fopensocket 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.
Reply to discussion (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);}
$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);}
During a local test, other computers can access my computer and run the test normally by using ip address, that is, if my test ip address is 192.168.10.60,
Other computers can use http: // 192.168.10.60/write. php;
But put the program on the server, the server ip address is assumed to be 192.168.10.3,
Run but cannot be executed.
The connection mode is 192.168.10.3. when fputs are connected, the absolute path must be written ...... What is the situation?
Isn't that normal?
Put it at 192.168.10.3.
It's not localhost. of course we need to use an absolute ip address for access. what's the problem?
Isn't that normal?
Two points abnormal
1. when I use my local machine as the test host, other machines can access my local machine and run normally when I use localhost. when I put the program on the server, I cannot access the server from my local machine;
2. do I mean to write absolute paths when fsocketopen creates a link? for example, if the program is stored in the ca/ma directory under the web directory
The fwrite path should be 192.168.10.3/ca/ma/1.php, even if the write program and the 1. php program are placed in the same directory, this is also required.
However, when I put it locally, it is normal to access the local computer from other computers. Windows is used locally and linux is used as the server. why is it because of the OS relationship?
1. The program runs on your machine, so it is normal to access it with localhost, and it is normal to access it with the ip address of your machine.
2. when the program is migrated to the server, localhost can also be accessed. However, due to the special nature of the server, the ing from 127.0.0.1 to localhost may fail.