[英]How to get contents of IP address in PHP
Im trying to use PHP file_get_contents for an IP. 我正在尝试将PHP file_get_contents用于IP。 Example:
例:
echo file_get_contents("1.22.22:2334/pay");
However PHP And Curl does not return the contents of the IP address, How would i go about doing this? 但是PHP And Curl不会返回IP地址的内容,我该怎么做?
Thank you very much. 非常感谢你。
You should use curl as file_get_contents
requires allow_url_fopen
to be on in the php.ini config file (which is not always the case). 您应该使用curl,因为
file_get_contents
要求在php.ini配置文件中启用allow_url_fopen
(并非总是如此)。
With curl and IP only it should be like: 仅使用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);
Answer partly from: PHP cURL connect using IP address instead domain name 部分回答来自: PHP cURL使用IP地址代替域名进行连接
More information: https://www.php.net/manual/de/book.curl.php 更多信息: https : //www.php.net/manual/de/book.curl.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.