假如我们使用curl请求一个网站,如果这个网站域名在本地host中也存在,curl默认会请求本地,但是我们可以自己设置解析到哪个ip。
(1).设置朋友的博客网站主机和ip,请求测试正确返回远程网站内容
<?php
$ip = '47.106.110.119';
$host = 'www.php20.cn';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Host:'.$host;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
file_put_contents('1.txt', $result);
var_dump($result);
//输出<!DOCTYPE html><html><head><meta charset="UTF-8"><title>仙士可博客,技术博客,php,技术分享,php博客,</title>(2).设置请求ip为本地,输出本地网站的内容
<?php
$ip = '127.0.0.1';
$host = 'www.php20.cn';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Host:'.$host;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
file_put_contents('1.txt', $result);
var_dump($result);
//输出本地站点未测试https
也可以试试百度的方法
curl_setopt($curl, CURLOPT_INTERFACE, 'ip');
上家公司开发医院挂号系统,系统采用GBK编码。ajax发送的中文用户名让PHP保存为cookie出现乱码的解决方案。1.Javascript变量var user=document.getElementById('user').innerText; user=escape(u...
项目需要使用websocket推送最新订单,客户服务器非linux不支持swoole,因此使用原生,直接上代码(1).PHP服务端<?php ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set...
(1).config.php 配置文件<?php /** * RabbitMQ_Config */ $config = [ 'host' => ...
将jsonp转为PHP数组和对象。/** * jsonp转数组|Jsonp转json * @param string $jsonp jsonp字符串 * @param bool $as...
elasticsearch的操作都是基于http协议的,已经有现成的php类库,composer安装即可。{ "require": { &...
本教程使用的定时任务基于EasyTak,EasyTask官方文档:https://gitee.com/392223903/EasyTask由于tp3.2.x官方开发未考虑命令行支持和绝对路径开发的标准,因此我编写了一个支持的类来运行。1.在tp3.2.3根目录下安装easytaskcomposer&...