1. 抓取无访问控制文件
~~~
<?php
$ch = curl_init(); //初始化
curl_setopt($ch, CURLOPT_URL, "http://blog.51yip.com/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果把这行注释掉的话,就会直接输出
$result=curl_exec($ch);
curl_close($ch);
?>
~~~
2. 模拟登录
~~~
<?php
$user = "admin";
$pass = "admin";
$curlPost = "user=$user&pass=$pass";
$ch = curl_init(); //初始化一个CURL对象
//设置所需要抓取的URL
curl_setopt($ch, CURLOPT_URL, "http://localhost/edu/login.php");
//设置curl参数,要求结果是否输出到屏幕上,为true的时候是不返回到网页中假设0换成1的话,接下来的$data就需要echo一下。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
//post提交
curl_setopt($ch, CURLOPT_POST, 1);
//运行curl,请求网页。
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);
curl_close($ch);
?>
~~~