PHP gets a lot of remote host file content methods, such as: File_get_contents,fopen and so on.
<?php
Echo file_get_contents (' http://demo.fdipzone.com/test.php ');
? >
But if the same domain name corresponds to a different IP, for example demo.fdipzone.com corresponds to 3 IP192.168.100.101, 192.168.100.102, 192.168.100.103.
You cannot use file_get_contents to get the content of 192.168.100.101 because it is assigned to different hosts based on the load balancing principle, so it is not certain that each time you are accessing the 192.168.100.101 host.
If you want to set the IP host method locally, but if you need to access 192.168.100.101 in the same program, and then access 192.168.100.102, the method for setting IP specified host locally is not possible, because multiple IPs cannot be assigned the same domain name.
Therefore, you need to use the Fsockopen method to access different IP hosts and then access them through the header settings host.
Use Fsockopen to set the Allow_url_fopen in PHP.ini as on.
<?php
/**
* @param String $IP Host IP
* @param String $host Host domain name
* @param int $port Port
* @param String $url the URL to access
* @param int $timeout timeout
* @return String
*/
function Remote_visit ($ip, $host, $port, $url, $timeout) {
$errno = ';
$errstr = ';
$fp = Fsockopen ($ip, $port, $errno, $errstr, $timeout);
if (! $fp) {//Connect fail
return false;
}
$out = "Get ${url} http/1.1\r\n";
$out. = "Host: ${host}\r\n";
$out. = "connection:close\r\n\r\n";
Fputs ($fp, $out);
$response = ';
Read content
while ($row =fread ($fp, 4096)) {
$response. = $row;
}
Fclose ($FP);
$pos = Strpos ($response, "\r\n\r\n");
$response = substr ($response, $pos +4);
return $response;
}
echo remote_visit (' 192.168.100.101 ', ' demo.fdipzone.com ', '/test.php ', 90);
echo remote_visit (' 192.168.100.102 ', ' demo.fdipzone.com ', '/test.php ', 90);
echo remote_visit (' 192.168.100.103 ', ' demo.fdipzone.com ', '/test.php ', 90);
?>