網站 建設 php 模擬 post 提交 幾種 方法 欄目 網站開發 简体版
原文   原文鏈接

一、curl網站建設php

Php代碼
  1. $post_data = array();  
  2. $post_data['clientname'] = "test08";  
  3. $post_data['clientpasswd'] = "test08";  
  4. $post_data['submit'] = "submit";  
  5. $url='http://xxx.xxx.xxx.xx/xx/xxx/top.php';  
  6. $o="";  
  7. foreach ($post_data as $k=>$v)  
  8. {  
  9.     $o.= "$k=".urlencode($v)."&";  
  10. }  
  11. $post_data=substr($o,0,-1);  
  12. $ch = curl_init();  
  13. curl_setopt($ch, CURLOPT_POST, 1);  
  14. curl_setopt($ch, CURLOPT_HEADER, 0);  
  15. curl_setopt($ch, CURLOPT_URL,$url);  
  16. //爲了支持cookie  
  17. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');  
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);  
  19. $result = curl_exec($ch);  

二、fsockopen
Php代碼
  1. $URL=‘http://xxx.xxx.xxx.xx/xx/xxx/top.php';  
  2. $post_data['clientname'] = "test08";  
  3. $post_data['clientpasswd'] = "test08";  
  4. $post_data['submit'] = "ログイン";  
  5. $referrer="";  
  6. // parsing the given URL  
  7. $URL_Info=parse_url($URL);  
  8. // Building referrer  
  9. if($referrer==""// if not given use this script as referrer  
  10. $referrer=$_SERVER["SCRIPT_URI"];  
  11.    
  12. // making string from $data  
  13. foreach($post_data as $key=>$value)  
  14. $values[]="$key=".urlencode($value);  
  15.    
  16. $data_string=implode("&",$values);  
  17. // Find out which port is needed - if not given use standard (=80)  
  18. if(!isset($URL_Info["port"]))  
  19. $URL_Info["port"]=80;  
  20. // building POST-request:  
  21. $request.="POST ".$URL_Info["path"]." HTTP/1.1\n";  
  22. $request.="Host: ".$URL_Info["host"]."\n";  
  23. $request.="Referer: $referrer\n";  
  24. $request.="Content-type: application/x-www-form-urlencoded\n";  
  25. $request.="Content-length: ".strlen($data_string)."\n";  
  26. $request.="Connection: close\n";  
  27. $request.="\n";  
  28. $request.=$data_string."\n";  
  29. $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);  
  30. fputs($fp$request);  
  31. while(!feof($fp)) {  
  32.     $result .= fgets($fp, 128);  
  33. }  
  34. fclose($fp);  

三、其它還有 網站建設

Snoopy 類 :sourceforge.net/projects/snoopy/ (fblww-0307)cookie

相關文章
相關標籤/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。
本站公眾號
   歡迎關注本站公眾號,獲取更多信息