Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. public function info($user = false) {
  2.  
  3. if ($user === false) {
  4. Url::redirect('get');
  5. }
  6.  
  7. $url = 'https://twitter.com';
  8.  
  9. $this->CurlTwitterUserInfo = new CurlTwitterUserInfo($url, $followLocation = true, $timeOut = 30, $maxRedirects = 4, $binaryTransfer = false, $includeHeader = true, $noBody = false);
  10. $this->CurlTwitterUserInfo->setCookieFileLocation(DOCROOT . 'cookies' . DS . $this->CurlTwitterAuth->_authUsername . '.txt');
  11. $this->CurlTwitterUserInfo->setUserAgent($_SERVER['HTTP_USER_AGENT']);
  12. $this->CurlTwitterUserInfo->makeCurlInfo($user);
  13.  
  14. //var_dump($this->CurlTwitterUserInfo->getHttpStatus());
  15. }
  16.  
  17. <?php
  18.  
  19. class CurlTwitterUserInfo {
  20.  
  21. protected $_userAgent;
  22. protected $_url;
  23. protected $_followLocation;
  24. protected $_timeOut;
  25. protected $_maxRedirects;
  26. protected $_cookie;
  27. protected $_cookieFileLocation = '';
  28. protected $_post;
  29. protected $_postFields;
  30. protected $_referer = '';
  31. protected $_session;
  32. protected $_webPage;
  33. protected $_includeHeader;
  34. protected $_noBody;
  35. protected $_status;
  36. protected $_binaryTransfer;
  37.  
  38. public $_authentication = 0;
  39. public $_authUsername = '';
  40. public $_authPassword = '';
  41.  
  42. public function __construct($url, $followLocation = true, $timeOut = 30, $maxRedirects = 4, $binaryTransfer = false, $includeHeader = false, $noBody = false) {
  43.  
  44. $this->_url = $url;
  45. $this->_followLocation = $followLocation;
  46. $this->_timeOut = $timeOut;
  47. $this->_maxRedirects = $maxRedirects;
  48. $this->_noBody = $noBody;
  49. $this->_includeHeader = $includeHeader;
  50. $this->_binaryTransfer = $binaryTransfer;
  51. }
  52.  
  53. public function useAuth($use) {
  54. $this->_authentication = 0;
  55.  
  56. if ($use === true) {
  57. $this->_authentication = 1;
  58. }
  59. }
  60.  
  61. public function setUsername($username) {
  62. $this->_authUsername = $username;
  63. }
  64.  
  65. public function setPassword($password) {
  66. $this->_authPassword = $password;
  67. }
  68.  
  69. public function setReferer($referer) {
  70. $this->_referer = $referer;
  71. }
  72.  
  73. public function setCookieFileLocation($path) {
  74. $this->_cookieFileLocation = $path;
  75. }
  76.  
  77. public function setPost($postFields) {
  78. $this->_post = true;
  79. $this->_postFields = $postFields;
  80. }
  81.  
  82. public function setUserAgent($userAgent) {
  83. $this->_userAgent = $userAgent;
  84. }
  85.  
  86. public function makeCurlInfo($user) {
  87.  
  88. $get_user_info = curl_init();
  89. curl_setopt_array($get_user_info, [
  90. CURLOPT_URL => $this->_url . '/' . $user,
  91. CURLOPT_CUSTOMREQUEST => 'GET',
  92. CURLOPT_RETURNTRANSFER => true,
  93. CURLOPT_SSL_VERIFYPEER => false,
  94. CURLOPT_SSL_VERIFYHOST => 2,
  95. CURLOPT_HTTPHEADER => [
  96. "Content-type:text/html;charset=utf-8",
  97. ],
  98. CURLOPT_FOLLOWLOCATION => $this->_followLocation,
  99. CURLOPT_USERAGENT => $this->_userAgent,
  100. CURLOPT_COOKIEFILE => $this->_cookieFileLocation,
  101. CURLOPT_COOKIEJAR => $this->_cookieFileLocation,
  102. CURLOPT_COOKIESESSION => true,
  103. CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
  104. CURLOPT_POSTREDIR => 2,
  105. CURLOPT_AUTOREFERER => 1,
  106. CURLOPT_MAXREDIRS => $this->_maxRedirects,
  107. CURLOPT_ENCODING => "gzip"
  108. ]
  109. );
  110.  
  111. if ($this->_includeHeader) {
  112. curl_setopt_array($get_user_info, [CURLOPT_HEADER => true]);
  113. }
  114.  
  115. $this->_webPage = curl_exec($get_user_info);
  116.  
  117. $this->_status = curl_getinfo($get_user_info, CURLINFO_HEADER_SIZE);
  118. $header = substr($this->_webPage, 0, $this->_status);
  119. $body = substr($this->_webPage, $this->_status);
  120.  
  121. $dom = new DOMDocument('5.0', 'utf-8');
  122. @$dom->loadHTML($body);
  123.  
  124. $data = json_decode($dom->getElementById('init-data')->getAttribute('value'));
  125.  
  126. return $data->profile_user;
  127. }
  128.  
  129. public function getHttpStatus() {
  130. return $this->_status;
  131. }
  132.  
  133. public function __tostring() {
  134. return $this->_webPage;
  135. }
  136.  
  137. }
  138.  
  139. @$dom->loadHTML($body);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement