Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. class Dakota_Tools_Helper_Data extends Mage_Core_Helper_Abstract
  2. {
  3. public function curlGetUrlContent($url, $header = false)
  4. {
  5. $crl = curl_init();
  6. $timeout = 5;
  7. curl_setopt ($crl, CURLOPT_URL,$url);
  8. curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
  10. if($header) {
  11. curl_setopt($crl, CURLOPT_HTTPHEADER, $header);
  12. }
  13. $ret = curl_exec($crl);
  14. curl_close($crl);
  15. return $ret;
  16. }
  17.  
  18. function curlPutUrlContent($url, $fields, $header = false)
  19. {
  20. $fields_string = http_build_query($fields);
  21. $crl = curl_init();
  22. $timeout = 5;
  23.  
  24. curl_setopt($crl, CURLOPT_URL, $url);
  25. curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "PUT");
  26. curl_setopt($crl, CURLOPT_POSTFIELDS, $fields_string);
  27. curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
  28. curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
  29. curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
  30. if($header) {
  31. curl_setopt($crl, CURLOPT_HTTPHEADER, $header);
  32. }
  33.  
  34. $ret = curl_exec($crl);
  35. curl_close($crl);
  36.  
  37. return $ret;
  38. }
  39.  
  40. function curlPostUrlContent($url, $fields, $header = false)
  41. {
  42. $fields_string = '';
  43. foreach($fields as $key=>$value) {
  44. $fields_string .= $key.'='.urlencode($value).'&';
  45. }
  46. rtrim($fields_string, '&');
  47.  
  48. $crl = curl_init();
  49. $timeout = 5;
  50.  
  51. curl_setopt($crl, CURLOPT_URL,$url);
  52. curl_setopt($crl, CURLOPT_POST, count($fields));
  53. curl_setopt($crl, CURLOPT_POSTFIELDS, $fields_string);
  54. curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
  55. curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
  56. curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
  57. $ret = curl_exec($crl);
  58.  
  59. curl_close($crl);
  60. return $ret;
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement