Advertisement
Guest User

cURL PHP 7 Object Oriented

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