Advertisement
Guest User

cURL PHP 7 Orientado a Objectos

a guest
Mar 5th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <?php
  2.  
  3. class cURL
  4. {
  5. public $email;
  6. public $senha;
  7. var $callback = false;
  8.  
  9. public function getStr($string,$start,$end)
  10. {
  11. $str = explode($start,$string);
  12. $str = explode($end,$str[1]);
  13. return $str[0];
  14. }
  15.  
  16. private function setCallback($func_name)
  17. {
  18. $this->callback = $func_name;
  19. }
  20.  
  21. public function doRequest($method, $url)
  22. {
  23. $ch = curl_init();
  24. curl_setopt($ch, CURLOPT_URL, $url);
  25. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  26. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  28. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  29. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  30. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  31. curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
  32. curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  33. curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd().'/cookie.txt');
  34. curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd().'/cookie.txt');
  35. curl_setopt($ch, CURLOPT_REFERER, '');
  36. curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
  37. if ($method == 'POST')
  38. {
  39. curl_setopt($ch, CURLOPT_POST, 1);
  40. curl_setopt($ch, CURLOPT_POSTFIELDS, "username={$this->email}&password={$this->senha}&recaptchaResponse=FALSE");
  41. }
  42. $data = curl_exec($ch);
  43. curl_close($ch);
  44.  
  45. if ($data)
  46. {
  47. if ($this->callback)
  48. {
  49. $callback = $this->callback;
  50. $this->callback = false;
  51. return call_user_func($callback, $data);
  52. }
  53. else
  54. {
  55. return $data;
  56. }
  57. }
  58. else
  59. {
  60. return curl_error($ch);
  61. }
  62. }
  63.  
  64. public function get($url)
  65. {
  66. return $this->doRequest('GET', $url, 'NULL');
  67. }
  68.  
  69. public function post($url)
  70. {
  71. return $this->doRequest('POST', $url);
  72. }
  73. }
  74.  
  75. $cURL = new cURL;
  76. $cURL->email = "Email";
  77. $cURL->senha = "Senha";
  78.  
  79. echo $cURL->post('https://www.netshoes.com.br/login');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement