PHP CURL 은 아 날로 그 로그 인 을 실현 하고 파일 작업 예 시 를 업로드 합 니 다.

이 글 은 PHP CURL 이 아 날로 그 로그 인 을 실현 하고 파일 을 업로드 하 는 작업 을 실례 로 다 루 고 있다.여러분 께 참고 하도록 공유 하 겠 습 니 다.구체 적 으로 는 다음 과 같 습 니 다.

<?php
header('content-type:text/html;charset=gb2312');
//                   ,                   
//       php5.3        @,         new CURLfile()        
//           header         ,           。     ,     。
function curl_form($post_data,$sumbit_url,$http_url,$cookie_file){
  $headers = array();
  $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  $headers[] = 'Cache-Control: max-age=0';
  $headers[] = 'Accept-Encoding: gzip, deflate';
  $headers[] = 'Origin: http://my.***.com';
  $headers[] = 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3';
  $headers[] = 'Upgrade-Insecure-Requests: 1';
  $headers[] = 'Content-Type: application/x-www-form-urlencoded';
  $headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0';
  $headers[] = 'Connection: keep-alive';
//  $headers[] = 'Cookie: ASPSESSIONIDCCTCTQQC=KBGLPDKBIKDIDCBGFOKNMKOE';
  //   
  $ch = curl_init();
  //    
  curl_setopt($ch, CURLOPT_URL, $sumbit_url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//         ,0   ,1    
  curl_setopt($ch, CURLOPT_HEADER, 0);//    ,        ,1   ,0    
  curl_setopt($ch, CURLOPT_REFERER, $http_url);
  //    ,           0
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch,CURLOPT_PROXY,'127.0.0.1:8888');
//  curl_setopt($ch, CURLOPT_ENCODING, "");
//  curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  //       
  $output = curl_exec($ch);
  if($output === FALSE)
  {
    echo "<br/>","cUrl Error:".curl_error($ch);
  }else{
    return $output;
  }
  //    cURL  
  curl_close($ch);
}
$temp = array();
$temp['title'] = iconv( "utf-8", "gb2312//IGNORE" , "     ");
$temp['ly'] = iconv( "utf-8", "gb2312//IGNORE" , "      ");
$temp['classid'] = iconv( "utf-8", "gb2312//IGNORE" , "7159");
$temp['newssort'] = iconv( "utf-8", "gb2312//IGNORE" , "1");
$temp['panduan'] = iconv( "utf-8", "gb2312//IGNORE" , "0");
$temp['submit_button'] = iconv( "utf-8", "gb2312//IGNORE" , "  ");
$temp['addr'] = iconv( "utf-8", "gb2312//IGNORE" , "bjcanyin");
$temp['ContentBg'] = "";
$temp['newss'] = iconv( "utf-8", "gb2312//IGNORE" , htmlspecialchars_decode("<p>           </p><p><img alt=\"\" 
src=\" http://localhost/super/Uploads/img/2017-08-10/598c145a9527e.jpg\" style=\"height:243px; width:324px\" /></p>", ENT_QUOTES));
$cookie_file = dirname(__FILE__)."/jdzj.tmp";
$sumbit_url = "http://***/news/***.asp";
$http_url="http://***/news/***.asp?act=addok";
$img = curl_form($temp,$http_url,$sumbit_url,$cookie_file);
var_dump($img);

PS:PHP curl 옵션 에 대한 자세 한 설명 은 참고 하 시기 바 랍 니 다https://www.jb51.net/article/39331.htm
더 많은 PHP 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.
본 논문 에서 말 한 것 이 여러분 의 PHP 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기