Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function retrieveURL($relativeURL){
- $uname = "user"; //this is the privileged user to the relative url we want
- $upswd = "pass";
- $domain = $_SERVER['HTTP_HOST'];
- $prefix = $_SERVER['HTTPS'] ? 'https://' : 'http://';
- $url_get_key = $prefix.$domain."index.php?option=com_users";
- //GET return & key
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url_get_key );
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
- curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt'); //as far as i understand, this stores a *new* session to a cookie file
- curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
- curl_setopt($ch, CURLOPT_HEADER, 0 );
- $results = curl_exec($ch);
- preg_match_all("(<input type="hidden" name="return" value="(.*)" />)siU", $results, $matches1); //Should not be needed if username and password are correct
- preg_match_all("(<input type="hidden" name="(.*)" value="1" />(.*)</fieldset>)iU", $results, $matches2); //Same as above
- // POST
- $url_post = $prefix.$domain."index.php?option=com_users&task=user.login";
- $postdata = "username=".urlencode($uname)."&password=".urlencode($upswd)."&return=".urlencode($matches1[1][0])."&".urlencode($matches2[1][0])."=1";
- curl_setopt($ch, CURLOPT_URL, $url_post);
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
- $results1 = curl_exec($ch);
- $url_data = $prefix.$domain.$relativeURL;
- curl_setopt($ch, CURLOPT_URL, $url_data); //Now we can retrieve the proper url
- $results2 = curl_exec($ch);
- $error = curl_error($ch);
- $errno = curl_errno($ch);
- curl_close($ch);
- return $results2; //could probably use a bit more error checking
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement