php curl 에서 자주 사용 하 는 5 가지 전형 적 인 예

3436 단어 php컬.예시
저 는 phop,curl 로 주로 데 이 터 를 캡 처 합 니 다.물론 우 리 는 다른 방법 으로 캡 처 할 수 있 습 니 다.예 를 들 어 fsockopen,fileget_내용 등.하지만 직접 접근 할 수 있 는 페이지 만 잡 을 수 있 습 니 다.페이지 접근 제어 가 있 는 페이지 를 잡 거나 로그 인 한 페이지 를 잡 으 려 면 어렵 습 니 다.
1,무 접근 제어 파일 캡 처

<?php 
 $ch = curl_init(); 
 curl_setopt($ch, CURLOPT_URL, "http://localhost/mytest/phpinfo.php"); 
 curl_setopt($ch, CURLOPT_HEADER, false); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //          ,       
 $result=curl_exec($ch); 
 curl_close($ch); 
 ?> 
2,대리 로 캡 처
왜 대리 로 캡 처 를 해 야 합 니까?구 글 의 경우 구 글 의 데 이 터 를 잡 으 러 가면 짧 은 시간 안에 자주 잡 으 면 잡 을 수 없습니다.구 글 이 ip 주 소 를 제한 할 때 대 리 를 바 꿔 서 다시 잡 을 수 있 습 니 다.

<pre name="code" class="php"><?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); 
 curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); 
 curl_setopt($ch, CURLOPT_PROXY, 125.21.23.6:8080); 
 //url_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');       ,     
 $result=curl_exec($ch); 
 curl_close($ch); 
 ?> 

3,post 데이터 후,데이터 캡 처
데이터 제출 데 이 터 를 따로 말씀 드 리 겠 습 니 다.curl 을 사용 할 때 데이터 교환 이 있 을 때 가 많 기 때문에 중요 합 니 다.

<?php 
 $ch = curl_init(); 
 /*         ,                  
 *  array('name'=>serialize(array('tank','zhang')),'sex'=>1,'birth'=>'20101010') 
 *  array('name'=>array('tank','zhang'),'sex'=>1,'birth'=>'20101010')      */ 
 $data = array('name' => 'test', 'sex'=>1,'birth'=>'20101010'); 
 curl_setopt($ch, CURLOPT_URL, 'http://localhost/mytest/curl/upload.php'); 
 curl_setopt($ch, CURLOPT_POST, 1); 
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
 curl_exec($ch); 
 ?> 
upload.php 파일 에서 printr($_POST);curl 을 이용 하면 upload.php 출력 내용 을 추출 할 수 있 습 니 다.Array([name]=>test[sex]=>1[birth]=>20101010)
4.페이지 접근 제어 가 있 는 페이지 를 캡 처 합 니 다.

이전에 한 편 을 쓴 적 이 있 는데,페이지 접근 제어 의 세 가지 방법 에 관심 이 있 으 면 한번 볼 수 있다.
위 에서 언급 한 방법 으로 잡 으 면 다음 과 같은 실 수 를 할 것 이다.
You are not authorized to view this page
You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.
이 럴 때 우 리 는 CURLOPTUSERPWD 가 검증 을 하 러 왔 습 니 다.

<?php 
 $ch = curl_init(); 
 curl_setopt($ch, CURLOPT_URL, "http://club-china"); 
 /*CURLOPT_USERPWD              
 *        htpasswd       。*/ 
 //curl_setopt($ch, CURLOPT_USERPWD, 'user:password'); 
 curl_setopt($ch, CURLOPT_HTTPGET, 1); 
 curl_setopt($ch, CURLOPT_REFERER, "http://club-china"); 
 curl_setopt($ch, CURLOPT_HEADER, 0); 
 $result=curl_exec($ch); 
 curl_close($ch); 
 ?> 
이상 의 php curl 에서 자주 사용 하 는 5 가지 전형 적 인 예 는 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 께 참고 가 되 고 저희 도 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기