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

问题描述 投票:1回答:1

我试图使用PHP file_get_contents为IP。例:

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

但是,PHP和Curl不会返回IP地址的内容,我将如何进行此操作?

非常感谢你。

php curl file-get-contents
1个回答
0
投票

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

只有卷曲和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);      

部分答案来自:PHP cURL connect using IP address instead domain name

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

© www.soinside.com 2019 - 2024. All rights reserved.