![](/img/trans.png)
[英]file_get_contents/curl PHP Function Not Working For IP Address
[英]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地址代替域名进行连接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.