PROXY Scripts.

Who/What/Where/Why?

To run php scripts located on this site, you will need to put a "proxy script" on your site, where you host your pages. Otherwise web browsers will complain about security violations.

Firefox will fail quietly, but IE will say:
"To help protect your security, Internet Explorer has restricted this file from showing active content that coule access your computer. Click here for options..."

We have chosen to modify #4. See code and comments below.

Here is a collection of proxy scripts collected over time with where they came from. If you decide to modify them to make them work for this site, please send us a copy so we can post them for everyone.

1

Came from here.

Here is a ASP Proxy Script.

<!-- Code starts Below this line -->
<%
set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
strURL = Request("url")"
objHttp.open "GET", strURL, False
objHttp.Send

If objHttp.status = 200 Then
    Response.Expires = 90
    Response.ContentType = Request("mimeType")
    Response.BinaryWrite objHttp.responseBody
    set objHttp = Nothing
End If
%>
<!-- Code ends above this line -->

Usage:

http://yourserver.com/proxy.asp?url=<url_encoded_desitnation_url>[&mimeType=<mimeType>]

Example:

http://yourserver.com/proxy.asp?url=http%3A//www.templatesoft.com/images/16596.jpg&mimeType=image/jpg

2

Came from here.

PHP Script using cURL. Aside from PHP, you will need to install CURL if you don't have it already on your server to run it.

<?php
// PHP Proxy
// Responds to both HTTP GET and POST requests
//
// Author: Abdul Qabiz
// March 31st, 2006
//

// Get the url of to be proxied
// Is it a POST or a GET?
$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
$headers = ($_POST['headers']) ? $_POST['headers'] : $_GET['headers'];
$mimeType =($_POST['mimeType']) ? $_POST['mimeType'] : $_GET['mimeType'];

//Start the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['url']) {
 $postvars = '';
 while ($element = current($_POST)) {
   $postvars .= key($_POST).'='.$element.'&';
   next($_POST);
 }
 curl_setopt ($session, CURLOPT_POST, true);
 curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, ($headers == "true") ? true : false);

curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$response = curl_exec($session);

if ($mimeType != "")
{
// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: ".$mimeType);
}

echo $response;

curl_close($session);

?>

Usage:-

http://yourserver.com/proxy.php?url=<url_encoded_desitnation_url>[&mimeType=<mimeType>]

Examples:-

To load XML/Text:
http://yourserver.com/proxy.php?url=http%3A//abdulqabiz.com/blog/index.xml

 

3

From here:

From this, there's a way to build PHP5, curl-less proxy:

<?php
function do_post_request($url, $data, $optional_headers = null)
{
 $params = array('http' => array(
 'method' => 'POST',
 'content' => $data
 ));
 if ($optional_headers !== null) {
   $params['http']['header'] = $optional_headers;
 }
 $ctx = stream_context_create($params);
 $fp = @fopen($url, 'rb', false, $ctx);
 if (!$fp) {
   throw new Exception("Problem with $url, $php_errormsg");
 }
 $response = @stream_get_contents($fp);
 if ($response === false) {
   throw new Exception("Problem reading data from $url, $php_errormsg");
 }
 return $response;
}
?>

(12:09)Chad: Instead of this:
$data = array ('username' => $username, 'first_name' => $first_name, 'last_name' = $last_name); $data = http_build_query($data);
Do this:
$data = http_build_query($_POST);

4

Here's a good one from the Yahoo folkes. A simple web proxy, written in PHP

Here's a version that WORKS. Modified code is right here. Cut and paste it into a callzip.php and put it on your server in the same folder as the page that makes the lookup calls. If this doesn't work, see if you need to install CURL library for your PHP, if you don't have it already.

<?php
// Author: Jason Levitt
// December 7th, 2005
//

//define ('HOSTNAME', 'http://search.yahooapis.com/');
// Do not make this a pass-in parameter as it would be a huge security flaw.
define ('HOSTNAME', 'http://itbsllc.com/');
// could shoose to pass in the path as a parameter if you want to make it more flexible
define ('path', 'zip/zip.php');

// Get the REST call path from the AJAX application
// Is it a POST or a GET?
//$path = ($_POST['yws_path']) ? $_POST['yws_path'] : $_GET['yws_path'];
$url = HOSTNAME.path;
// Enable this for debugging:
//echo $url."<p>";

// Open the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
//if ($_POST['yws_path']) {
if ($_POST['zipcode']) {
  $postvars = '';
  while ($element = current($_POST)) {
    $postvars .= key($_POST).'='.$element.'&';
    next($_POST);
  }
  curl_setopt ($session, CURLOPT_POST, true);
  curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// This one I saw elsewhere, see if you need it.
//curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);

// Make the call
$xml = curl_exec($session);

// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");

echo $xml;
curl_close($session);

?>

5 Google guys wrote one too. Similar to 4.