PHP Curl, retrieving Server IP Address

前端 未结 6 1168
迷失自我
迷失自我 2021-02-08 21:52

I\'m using PHP CURL to send a request to a server. What do I need to do so the response from server will include that server\'s IP address?

6条回答
  •  遥遥无期
    2021-02-08 22:20

    I think you should be able to get the IP address from the server with:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://stackoverflow.com");
    curl_exec($ch);
    $ip = curl_getinfo($ch,CURLINFO_PRIMARY_IP);
    curl_close($ch);
    echo $ip; // 151.101.129.69
    

提交回复
热议问题