If a domain name corresponds to multiple ips, there are multiple servers. How to access the url information of a specified server through curl. We know that the code for generally using curl to obtain url information is as follows
$url="https://www.iid.hk/";
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https request does not verify certificate and hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content=curl_exec($ch);
echo $content;
If you want to access the content of the ip server 39.99.204.74, you can change the domain name part of the request url to the ip method, and add the Host request header information. The specific sample code is as follows
$url='https://39.99.204.74/index.php';
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Host: www.iid.hk"));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https request does not verify certificate and hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$content=curl_exec($ch);
echo $content;
In versions above php5.5, it is supported to use CURLOPT_RESOLVE to set the corresponding ip address of the host.
$url='https://www.iid.hk/index.php';
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RESOLVE, ["www.iid.hk:443:39.99.204.74"]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https request does not verify certificate and hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$content=curl_exec($ch);
echo $content;
Among them, the CURLOPT_RESOLVE option provides a custom address and specifies the host and port. An array of strings containing host, port, and ip addresses, each element separated by a colon. Format:
array("example.com:80:127.0.0.1")