Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** d3B#g */
- error_reporting(E_ALL ^ E_NOTICE);
- ini_set('display_errors', TRUE);
- set_time_limit(15);
- /** meh codez is so fast I need to use sleep() to make it look like it's doing something */
- # sleep(rand(0,5));
- $url = $_GET['url'];
- if ( ! filter_var($url, FILTER_VALIDATE_URL))
- {
- exit(1);
- }
- /** dump var */
- $output = NULL;
- main($url, $output);
- echo $output;
- exit(1);
- /** main function */
- function main($url, &$output)
- {
- $http = new HTTP();
- $response = $http->curl($url);
- $headers = $http->parse_headers($response);
- if(isset($headers['location']))
- {
- $output .= sprintf('HTTP: %s, Length: %s, Redirected to: %s ', $headers['http'], $headers['content-length'], $headers['location']);
- main($headers['location'], $output);
- return;
- }
- if (empty($response))
- {
- /** (╯°□°)╯︵ ┻━┻ */
- $output = 'HTTP Request Failed.';
- return;
- }
- $output .= sprintf('HTTP: %s, Length: %s', $headers['http'], $headers['content-length']);
- }
- /** HTTP mockup class */
- class HTTP
- {
- function curl($url, $headers = array())
- {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1');
- curl_setopt($ch, CURLOPT_HEADER, TRUE);
- curl_setopt($ch, CURLOPT_NOBODY, TRUE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $data = curl_exec($ch);
- curl_close($ch);
- return $data;
- }
- function parse_headers($headers)
- {
- $headers = explode("\n", $headers);
- foreach($headers as $i => $header)
- {
- $value = explode(' ', $header);
- $key = $value[0];
- $key = strtolower(trim($key, ':'));
- if(strpos($key, 'http') !== false)
- {
- $key = 'http';
- }
- array_shift($value);
- $return[$key] = implode(' ', $value);
- }
- return $return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement