PHPBuilder - fopen() via proxy server



RSS Twitter
Snippets Http

fopen() via proxy server

by: NightOwl
|
August 26, 2003

Version: 1.0

Type: Function

Category: HTTP

License: GNU General Public License

Description: Fopen() normally does not support a proxy server. This function replaces the fopen() of an url via a proxy server. All comments welcome!



function pfopen($url) {
	
	
	$proxy_server = "MYPROXYSERVER";
	$proxy_port = 8080;


	if (substr($url, 0,7) <> 'http://') {
		return false;
	}


	$proxycon = fsockopen($proxy_server, $proxy_port, $errno, $errstr);



	fputs($proxycon,"GET ".$url." HTTP/1.0 \r\n\r\n");

	$reading_headers = true;
	while (!feof ($proxycon)) {
		$curline = fgets($proxycon, 4096);

		if ($curline=="\r\n") {
			$reading_headers = false;
		}
		if (!$reading_headers) {
			$filecontent .= $curline;
		}
	}

	fclose($proxycon);
	return $filecontent;


}

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
NightOwl

Comment:



Comment:

(Maximum characters: 1200). You have characters left.