Page 1 of 1

A php script to work as a type of Proxy? (using php headers)

Posted: Thu Sep 02, 2004 9:17 am
by intel352
I am an employee for a large company, which uses a proxy coupled with a webpage filter, to block websites which are deemed to not be work related. Personally, I find this rather annoying, lol, because it blocks harmless sites (news sites, google's toolbar site, etc), and almost always has them wrongly categorized with a reason for the block (I've come across more than one family site that was blocked as pr0n, lol).

I have my own webservers, and none of my own websites are blocked by the web proxy. So my thinking is that I could create a php script that will display websites as they were intended to be displayed, in a sort of web proxy.

I think this could be done by having a frame at the top of the html output, where the webaddress is entered, that you would like to view (simulating a browser). The webpage loads up, but using PHP headers, all content is renamed as if it were coming from the site hosting the proxy script (my website).

This method would allow for uninterrupted browsing, would not require my server to download any files, would just rename the sources and pass them on through.

What do you guys think? Sound feasible?
Does anyone know of any script that already exists, so that I don't have to re-invent the wheel? :-)

Posted: Thu Sep 02, 2004 9:50 am
by feyd
It's quite easy to build on your own. The one I built for myself uses curl and several regular expressions. However, the server always downloads the files first.. and has to if you want them altered so those pages still go through your server.

I will not post my script. This is a learning opportunity.

Posted: Thu Sep 02, 2004 10:03 am
by intel352
a dev that i work with on some projects, implemented this code into one of our modules for the Xoops CMS

Code: Select all

if (is_file($map_dl_location."/".$mapdlname)){
			$xoopsDB->queryF("UPDATE ".$xoopsDB->prefix("fatalquery_maps")." set map_dl_count=map_dl_count+1 where map_name='".$_GETї'file']."'");
			$fp=@fopen($map_dl_location."/".$mapdlname,"r");
			}
		if(isset($fp)) {
			$content_len = filesize($map_dl_location."/".$mapdlname);
			$content_file = fread($fp, $content_len);
			fclose($fp);
			@ob_end_clean();
			@ini_set('zlib.output_compression', 'Off');
			header('Pragma: public');
			header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
			header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
			header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
			header('Content-Transfer-Encoding: none');
			header('Content-Type: application/octetstream; name="'.$mapdlname.'"'); //This should work for IE & Opera
			header('Content-Type: application/octet-stream; name="'.$mapdlname.'"'); //This should work for the rest
			header('Content-Disposition: inline; filename="'.$mapdlname.'"');
			header("Content-length: $content_len");
			echo $content_file;
			exit();

i'm thinking something like that could be used to simply pass the files on from their original source, without the server needing to download the files.

Posted: Thu Sep 02, 2004 10:25 am
by feyd
that script downloads the file to the server.

Posted: Thu Sep 02, 2004 10:29 am
by intel352
lol, i reckon it would help if i bothered to read it, i just assumed (yes, i know what assuming does) that it just passes the file on through.


okay, sorry about that

Posted: Thu Sep 02, 2004 3:48 pm
by timvw
isn't it easier to setup a tunnel (http/dns/whatever) and then use a unrestricted proxy on your server?

Posted: Thu Sep 02, 2004 3:55 pm
by intel352
i wouldn't know, since i've never done that

documentation suggestions?