Curl

root

Well-Known Member
- CURLOPT_HEADER: nếu là true thì sẽ hiện thị header, false thì ko
PHP:
<?php
// khởi tạo 1 url mới
$ch = curl_init();
$url="http://svuit.com/forum.php"
// Thiết lập URL và đưa ra header
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);

// lấy URL và thực hiện chạy nó
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

  • Kết quả
Code:
[COLOR=#3E3E3E]HTTP/1.1 200 OK Date: Sat, 25 Jan 2014 15:07:22 
GMT Server: Apache X-Powered-By: PHP/5.3.27 
Cache-Control: private Pragma: private 
Set-Cookie: bb_lastvisit=1390662442; 
expires=Sun, 25-Jan-2015 15:07:22 GMT; 
path=/ Set-Cookie: bb_lastactivity=0; 
expires=Sun, 25-Jan-2015 15:07:22 GMT; 
path=/ Content-Length: 82981 Content-Type: text/html; 
charset=UTF-8
[/COLOR]
 

root

Well-Known Member
CURL với socks5 và Useragent
PHP:
<?php    
$ch = curl_init();        
$url = "http://whoer.net";        
$useragent = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";        
$socks = '74.132.8.66:27152';        
curl_setopt($ch,CURLOPT_URL,$url);        
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);        
curl_setopt($ch,CURLOPT_USERAGENT,$useragent);       
curl_setopt($ch,CURLOPT_PROXY,$socks);        
curl_setopt($ch,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);       
curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL,true);       
curl_setopt($ch,CURLOPT_TIMEOUT,10);        
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);        
$output = curl_exec($ch);        
curl_close($ch);        
echo $output;    
?>
 

root

Well-Known Member
Lấy thông tin resource 1 website

PHP:
if($output){        
$info = curl_getinfo($ch);               
echo "time =".$info['connect_time'];           
}
Ngoài ra còn thêm các Option tham khảo thêm tại đây

  • "url"
  • "content_type"
  • "http_code"
  • "header_size"
  • "request_size"
  • "filetime"
  • "ssl_verify_result"
  • "redirect_count"
  • "total_time"
  • "namelookup_time"
  • "connect_time"
  • "pretransfer_time"
  • "size_upload"
  • "size_download"
  • "speed_download"
  • "speed_upload"
  • "download_content_length"
  • "upload_content_length"
  • "starttransfer_time"
  • "redirect_time"
  • "certinfo"
​nguồn: http://www.php.net/manual/en/function.curl-getinfo.php
 
Top