CURL PHP Ready function !

meabed meabed is offline Offline Sep 12th, 2009, 10:19 pm |
0
This is CURL Ready function , to use it just call do post if the page you are calling has post variables , or get if it has get variables
Quick reply to this message  
PHP Syntax
  1. $random=rand(1, 100000);
  2. $cookie=$random . ".txt";
  3. $agent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
  4.  
  5. function doRequest($method, $url, $referer, $agent, $cookie, $vars) {
  6. $ch=curl_init();
  7. curl_setopt($ch, CURLOPT_URL, $url);
  8. if($referer != "") {
  9. curl_setopt($ch, CURLOPT_REFERER, $referer);
  10. }
  11. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  12. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  15. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  16. if ($method == 'POST') {
  17. curl_setopt($ch, CURLOPT_POST, 1);
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
  19. }
  20. if (substr($url, 0, 5) == "https") {
  21. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  23. }
  24. $data = curl_exec($ch);
  25. curl_close($ch);
  26. if ($data) {
  27. return $data;
  28. } else {
  29. return curl_error($ch);
  30. }
  31. }
  32.  
  33. function get($url, $referer, $agent, $cookie) {
  34. return doRequest('GET', $url, $referer, $agent, $cookie, 'NULL');
  35. }
  36.  
  37. function post($url, $referer, $agent, $cookie, $vars) {
  38. return doRequest('POST', $url, $referer, $agent, $cookie, $vars);
  39. }

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC