假如我们使用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');
项目需要使用websocket推送最新订单,客户服务器非linux不支持swoole,因此使用原生,直接上代码(1).PHP服务端<?php ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set...
开发com组件可以用c++,vc++,net,我比较熟悉net,演示用dnet(1).创建项目:启动vs2017,新建项目,选择Visual C# ->Windows桌面->类库通用windows(2). 修改Com项目:点击 项目->项目属性,再点击应用程序->程序集信息,...
逛公众号文章看到文章"php实现事件监听与触发的方法,你用过吗?",我就好奇了,php又不是asp.net的webform,哪里来的服务端事件监听。于是学习了一波。先看下监听类:class Event { /** &nbs...
(1).config.php 配置文件<?php /** * RabbitMQ_Config */ $config = [ 'host' => ...
参数中包含gb2312的字符串,返回结果是false或者null(不同PHP版本具有差异性)代码:<?php $dbms = 'mysql'; $host = '192.168.8.8'; $dbName =&n...
<?php /** * @throws Exception */ function curl() { throw new \Exception('err...