PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/core/lib/curl.php

http://phpfor.googlecode.com/
PHP | 68 lines | 64 code | 3 blank | 1 comment | 12 complexity | 829b193fdfa7c1910ce3905f55aca5c4 MD5 | raw file
  1. <?php
  2. class cURL {
  3. var $headers;
  4. var $user_agent;
  5. var $compression;
  6. var $cookie_file;
  7. var $proxy;
  8. function cURL($cookies=FALSE,$cookie='cookies.txt',$compression='gzip',$proxy='') {
  9. $this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
  10. $this->headers[] = 'Connection: Keep-Alive';
  11. $this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
  12. $this->user_agent = 'ShopEx Curl Client';
  13. $this->compression=$compression;
  14. $this->proxy=$proxy;
  15. $this->cookies=$cookies;
  16. //if ($this->cookies == TRUE) $this->cookie($cookie);
  17. }
  18. function cookie($cookie_file) {
  19. if (file_exists($cookie_file)) {
  20. $this->cookie_file=$cookie_file;
  21. } else {
  22. fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
  23. $this->cookie_file=$cookie_file;
  24. fclose($this->cookie_file);
  25. }
  26. }
  27. function get($url) {
  28. $process = curl_init($url);
  29. curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
  30. curl_setopt($process, CURLOPT_HEADER, 0);
  31. curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
  32. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
  33. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
  34. curl_setopt($process,CURLOPT_ENCODING , $this->compression);
  35. curl_setopt($process, CURLOPT_TIMEOUT, 5);
  36. if ($this->proxy) curl_setopt($cUrl, CURLOPT_PROXY, 'proxy_ip:proxy_port');
  37. curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
  38. curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
  39. $return = curl_exec($process);
  40. curl_close($process);
  41. return $return;
  42. }
  43. function post($url,$data) {
  44. $process = curl_init($url);
  45. curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
  46. curl_setopt($process, CURLOPT_HEADER, 1);
  47. curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
  48. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
  49. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
  50. curl_setopt($process, CURLOPT_ENCODING , $this->compression);
  51. curl_setopt($process, CURLOPT_TIMEOUT, 30);
  52. if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
  53. curl_setopt($process, CURLOPT_POSTFIELDS, $data);
  54. curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
  55. curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
  56. curl_setopt($process, CURLOPT_POST, 1);
  57. $return = curl_exec($process);
  58. curl_close($process);
  59. return $return;
  60. }
  61. function error($error) {
  62. echo "<center><div style='width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px'><b>cURL Error</b><br>$error</div></center>";
  63. die;
  64. }
  65. }