如何获取 PHP 中 IP 地址的内容

How to get contents of IP address in PHP

我正在尝试使用 PHP file_get_contents 作为 IP。示例:

echo file_get_contents("1.22.22:2334/pay");

但是 PHP 并且 Curl 没有 return IP 地址的内容,我该怎么做呢?

非常感谢。

您应该使用 curl,因为 file_get_contents 要求在 php.ini 配置文件中启用 allow_url_fopen(并非总是如此)。

只有 curl 和 IP 应该是这样的:

    // create curl resource 
    $ch = curl_init(); 

    // headers for ip only
    $headers = array("Host: www.myfaketopsite.com");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_URL, "https://1.22.22:2334/pay");

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output = curl_exec($ch); 

    // close curl resource to free up system resources 
    curl_close($ch);      

部分回答来自:

更多信息:https://www.php.net/manual/de/book.curl.php