原文来自:http://www.cmx8.cn/curl.html 例子一: 基本例子 基本例子 ﹤?php // 初始化一个 curl 对象 $curl = curl_init(); // 设置你需要抓取的url curl_setopt($curl, curlopt_url, 'http://www.cmx8.cn'); // 设置header curl_setopt($curl, curlopt_head
原文来自:http://www.cmx8.cn/curl.html
例子一: 基本例子
基本例子﹤?php
// 初始化一个 curl 对象
$curl = curl_init();
// 设置你需要抓取的url
curl_setopt($curl, curlopt_url, 'http://www.cmx8.cn');
// 设置header
curl_setopt($curl, curlopt_header, 1);
// 设置curl 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($curl, curlopt_returntransfer, 1);
// 运行curl,请求网页
$data = curl_exec($curl);
// 关闭url请求
curl_close($curl);
// 显示获得的数据
var_dump($data);?>
例子二: post数据
sendsms.php,其可以接受两个表单域,一个是电话号码,一个是短信内容。
post数据﹤?php
$phonenumber = '13812345678';
$message = 'this message was generated by curl and php';
$curlpost = 'pnumber=' . urlencode($phonenumber) . '&message=' . urlencode($message) . '&submit=send';
$ch = curl_init();
curl_setopt($ch, curlopt_url, 'http://www.lxvoip.com/sendsms.php');
curl_setopt($ch, curlopt_header, 1);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_postfields, $curlpost);
$data = curl_exec();
curl_close($ch);
?﹥例子三:使用代理服务器
使用代理服务器﹤?php
$ch = curl_init();
curl_setopt($ch, curlopt_url, 'http://www.cmx8.cn');
curl_setopt($ch, curlopt_header, 1);
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt($ch, curlopt_httpproxytunnel, 1);
curl_setopt($ch, curlopt_proxy, 'proxy.lxvoip.com:1080');
curl_setopt($ch, curlopt_proxyuserpwd, 'user:password');
$data = curl_exec();
curl_close($ch);
?﹥例子四: 模拟登录
curl 模拟登录 discuz 程序,适合dz7.0,将username改成你的用户名,userpass改成你的密码就可以了.
curl 模拟登录 discuz 程序
