Picatta Posted January 30, 2007 Share Posted January 30, 2007 So, I'm trying to make a new proxy in php. However, a problem I've run into is that it can't handle biary data. I'm thinking it is with the way I'm filtering the headers, but I'm not shure... (heres an example: http://multithreading.ath.cx:24/myproxy/proxy.php?page=http://www.mixfevers.com)Whenver I try to proxify an image, I get [quote]The image “http://localhost:24/myproxy/proxy.php?page=http://mixfevers.com/main/includes/images/block2.gif” cannot be displayed, because it contains errors.[/quote]I'm not shure what to do...[code]<?php if (!function_exists(str_ireplace)) { function str_ireplace($repit,$repl,$src) { return str_replace(strtolower($repit), strtolower($repl), strtolower($src)); } } function encode($url) { $old = array('://', 'page=', '?', '=', 'q'); $new = array('<[pro]>', '<[pgespchr]>', '<[qmark]>', '<[eqmark]>', '<[qchr]>'); $url = str_ireplace($old, $new, $url); return $url; } function decode($url) { $old = array('://', 'page=', '?', '=', 'q'); $new = array('<[pro]>', '<[pgespchr]>', '<[qmark]>', '<[eqmark]>', '<[qchr]>'); $url = str_ireplace($new, $old, $url); return $url; } if (!isset($_GET['page'])) { if (!isset($_GET['browse'])) { print " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\"> <head> <!-- Web proxy by Coprolal1an/Picatta/Alex Ray/minihacker316/Cracked.Anarchist //--> <title> A simple web mirror script </title> </head> <body> <form action='?browse' method='GET'> <div id='form'> URL: <input type='text' name='q' /><br /><br /> <input type='submit' value='browse' /> <input type='hidden' name='browse' /> </div> </form> </body> </html> "; } else { //Print frame page $page = $_GET['q']; //Get the requested page print " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <title> A simple web proxy </title> </head> <frameset rows='5%,*' scrolling='auto' border='0'> <frame src='?page&header' /> <frame src='?page=" . encodeurl($page) . "' /> <noframes> <body> myProxy web proxy by Coprolal1an requires a frame-enabled browser such as Firefox. </body> </noframes> </frameset> </html> "; } } elseif ((isset($_GET['page'])) AND (!isset($_GET['header']))) { //Print requested page $page = decode($_GET['page']); //Get the page the user requested $page = explode('://', $page); $prefix = $page[0]; $page = $page[1]; $page = explode('/', $page, 2); $host = explode('.', $page[0]); if (strpos($host[0], 'www') !== FALSE) { unset($host[0]); } $host = implode('.', $host); $path = '/' . $page[1]; if ($prefix == 'https') { $port = 443; $pre = 'ssl://www.'; } else { $port = 80; $pre = 'www.'; } $fp = fsockopen($pre . $host, $port, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET $path HTTP/1.1\r\n"; $out .= "Host: $pre$host\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { $buffer .= fgets($fp, 128); } fclose($fp); $buffer = explode('<', $buffer); $header = $buffer[0]; $header = preg_split("/\n/", $header); $lines = count($header); for ($int=0; $int<$lines; $int++) { $line = $header[$int]; if (!empty($line) AND (strpos($line,'Transfer-Encoding') === FALSE) AND (strpos($line,'Location:') === FALSE) AND (strpos($line,'location:') === FALSE)) { header($line); //print $line; } } $buffer[0] = "\n"; $buffer = implode('<', $buffer); $buffer = explode('0', $buffer); $end = count($buffer)-1; unset($buffer[$end]); $buffer = implode('0', $buffer); $buffer = preg_replace("/(http|https):\/\/(.*?)('|\"| )/", ("?page=$1://$2$3"), $buffer); print $buffer; } } else { print "Proxified page below<br />"; }?>[/code]It uses frame because I figured that would be easiest.NOTE; The encode and decode functions will eventually be for parsing urls. Link to comment https://forums.phpfreaks.com/topic/36287-help-making-a-php-proxy/ Share on other sites More sharing options...
Picatta Posted January 30, 2007 Author Share Posted January 30, 2007 bump Link to comment https://forums.phpfreaks.com/topic/36287-help-making-a-php-proxy/#findComment-173200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.