Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public function _post($endpoint = '', array $params = [], $cookieStorage = false) {
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, $endpoint);
  4. curl_setopt($ch, CURLOPT_POST, 1);
  5. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  7. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  8. if ($cookieStorage != FALSE) {
  9. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36');
  10. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieStorage);
  11. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieStorage);
  12. }
  13. $response = curl_exec($ch);
  14. curl_close($ch);
  15. return $response;
  16. }
  17.  
  18. public function login($username = '', $password = '') {
  19. $result = $this->_post(self::$BASE_URL . '/ucp.php?mode=login', [
  20. 'username' => $username,
  21. 'password' => $password,
  22. 'redirect' => '/viewforum.php',
  23. 'login' => 'Login',
  24. 'sid' => ''
  25. ], $this->cookieFile);
  26. if (preg_match('/' . $username . '/i', $result)) {
  27. return TRUE;
  28. } elseif (preg_match('/whoops/i', $result)) {
  29. return $result;
  30. } else {
  31. return FALSE;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement