簡體   English   中英

如何在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 And Curl不會返回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);      

部分回答來自: PHP cURL使用IP地址代替域名進行連接

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM