Put your tips and tricks online - Share your knowledge! Login | Register
 
 
  Search     Advanced search
 

Home | Ask Question | Add tip | My tips | Recent tips & tricks | Suggest a category | FAQ | Forums

 
 
 
 Category : Home > Programming > PHP > HTTP     

Script to view URLs through HTTP proxy server


This PHP function allows to view / download contents from websites on the Internet through a
proxy server, with or without proxy authentication. If no username / password supplied to the
function it will assume that proxy server does not require authentication.

<?php

	function proxy_url($proxy_url, $proxy_name, $proxy_port, $proxy_user, $proxy_pass) {

		$proxy_cont = '';

		$proxy_fp = fsockopen($proxy_name, $proxy_port);

		if (!$proxy_fp) {

			return false;

		}

		fputs($proxy_fp, "GET $proxy_url HTTP/1.0\r\nHost: $proxy_name\r\n");

		if (!empty($proxy_user) && !empty($proxy_pass)) {

			fputs($proxy_fp, "Proxy-Authorization: Basic " . base64_encode ("$proxy_user:$proxy_pass")
. "\r\n\r\n");

		}

		while(!feof($proxy_fp)) {

			$proxy_cont .= fread($proxy_fp,4096);

		}

		fclose($proxy_fp);

		$proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);

		return $proxy_cont;

	}

?>


  Options
 
   del.icio.us  |  newsvine  |  digg  |  furl  |  google  |  yahoo  |  Ma.gnolia  |  vigillar  |  reddit  |  technorati  |  icerocket  |  pubsub

       Rate this tip:    

Start discussion or add comment to this tip

  Details
Tip reference : #106
views : 351
Added on : 06/07/06
Submited by : h8dk97
 
Send a message Send a message Printer friendly output Printer friendly output
Display this member's tips Display this member's tips (172)
 
 
<< Previous
 Most viewed tips 
  Databases > Oracle > Security : How to unlock Oracle user account  
  Operating Systems > Unix : How to kill Unix user session  
  Databases > Oracle > Performance Tuning : How to enable trace in Oracle  
  Databases > Oracle : Kill user session  
   
  All categories
Databases | Programming | Hardware | Operating Systems | Networking | Internet | ERP / CRM | Games & Multimedia | Graphics & Design | Miscellaneous | Office Software | TipLib FAQ
 
 

Home |  FAQ |  Terms of Use |  Privacy Policy

© 2005 tiplib.com