Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <?php
  2. function retrieveURL($relativeURL){
  3. $uname = "user"; //this is the privileged user to the relative url we want
  4. $upswd = "pass";
  5. $domain = $_SERVER['HTTP_HOST'];
  6. $prefix = $_SERVER['HTTPS'] ? 'https://' : 'http://';
  7.  
  8. $url_get_key = $prefix.$domain."index.php?option=com_users";
  9.  
  10. //GET return & key
  11. $ch = curl_init();
  12. curl_setopt($ch, CURLOPT_URL, $url_get_key );
  13. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
  15.  
  16. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt'); //as far as i understand, this stores a *new* session to a cookie file
  17. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
  18. curl_setopt($ch, CURLOPT_HEADER, 0 );
  19.  
  20. $results = curl_exec($ch);
  21.  
  22. preg_match_all("(<input type="hidden" name="return" value="(.*)" />)siU", $results, $matches1); //Should not be needed if username and password are correct
  23. preg_match_all("(<input type="hidden" name="(.*)" value="1" />(.*)</fieldset>)iU", $results, $matches2); //Same as above
  24.  
  25. // POST
  26. $url_post = $prefix.$domain."index.php?option=com_users&task=user.login";
  27. $postdata = "username=".urlencode($uname)."&password=".urlencode($upswd)."&return=".urlencode($matches1[1][0])."&".urlencode($matches2[1][0])."=1";
  28. curl_setopt($ch, CURLOPT_URL, $url_post);
  29. curl_setopt($ch, CURLOPT_POST, TRUE);
  30. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  31. $results1 = curl_exec($ch);
  32.  
  33. $url_data = $prefix.$domain.$relativeURL;
  34. curl_setopt($ch, CURLOPT_URL, $url_data); //Now we can retrieve the proper url
  35.  
  36. $results2 = curl_exec($ch);
  37. $error = curl_error($ch);
  38. $errno = curl_errno($ch);
  39.  
  40. curl_close($ch);
  41. return $results2; //could probably use a bit more error checking
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement