I am building a web map application using Openlayers and Geoserver. Both the application and the geoserver are hosted on amazon. I would like to include a feature info tool and am using WMSGetFeatureInfo to perform WMS query. However, when I click on the map, it returns an empty popup. Here is how I set up the proxy host and the feature info control in the html file:

 // Set up Proxy Host
OpenLayers.ProxyHost = "proxy.php?url=";

// Add feature info control
            var featureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
                url: 'http://my_site:8080/geoserver/opengeo/wms', 
                layerUrls: ["http://my_site:8080/geoserver/gwc/service/wms"],
                title: 'Identify features by clicking',
                queryVisible: true,
                eventListeners: {
                    "getfeatureinfo": function(event) {
                        // Show Popup
                        map.addPopup(new OpenLayers.Popup.FramedCloud(

when i try to load http://my_site.com/proxy.php?url=http://www.google.com on my browser. I got the following message:

This page contains the following errors: error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

The following is my proxy script (proxy.php):

License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
$Id: proxy.php 3650 2007-11-28 00:26:06Z rdewit $

// Description:
// Script to redirect the request http://host/proxy.php?url=http://someUrl
// to http://someUrl .
// This script can be used to circumvent javascript's security requirements
// which prevent a URL from an external web site being called.
// Author: Nedjo Rogers

// read in the variables

if(array_key_exists('HTTP_SERVERURL', $_SERVER)){ 
$parsed = parse_url($onlineresource);
$host = @$parsed["host"];
$path = @$parsed["path"] . "?" . @$parsed["query"];
if(empty($host)) {
  $host = "localhost";
$port = @$parsed['port'];
$contenttype = @$_REQUEST['contenttype'];
if(empty($contenttype)) {
  $contenttype = "text/xml";
// define content type
header("Content-type: " . $contenttype);

if(empty($data)) {
  $result = send_request();
else {
  // post XML
  $posting = new HTTP_Client($host, $port, $data);
  $result = $posting->send_request();

// strip leading text from result and output result
$pos = strpos($result, "<");
if($pos > 1) {
  $result = substr($result, $pos, $len);
//$result = str_replace("xlink:","",$result);
echo $result;

// define class with functions to open socket and post XML
// from http://www.phpbuilder.com/annotate/message.php3?id=1013274 by Richard Hundt

class HTTP_Client { 
  var $host; 
  var $path;
  var $port; 
  var $data; 
  var $socket; 
  var $errno; 
  var $errstr; 
  var $timeout; 
  var $buf; 
  var $result; 
  var $agent_name = "MyAgent"; 
  //Constructor, timeout 30s 
  function HTTP_Client($host, $port, $data, $timeout = 30) { 
    $this->host = $host; 
    $this->port = $port;
    $this->data = $data;
    $this->timeout = $timeout; 

  //Opens a connection 
  function connect() { 
    $this->socket = fsockopen($this->host, 
      return false; 
      return true; 

  //Set the path 
  function set_path($path) { 
    $this->path = $path; 

  //Send request and clean up 
  function send_request() { 
    if(!$this->connect()) { 
      return false; 
    else { 
      $this->result = $this->request($this->data);
      return $this->result; 

  function request($data) { 
    $this->buf = ""; 
      "POST $this->path HTTP/1.0\r\n". 
      "User-Agent: $this->agent_name\r\n". 
      "Content-Type: application/xml\r\n". 
      "Content-Length: ".strlen($data). 

      $this->buf .= fgets($this->socket, 2048); 
      return $this->buf; 

  function close() {

function send_request() {
  global $onlineresource;
  $ch = curl_init();
  $timeout = 5; // set to zero for no timeout

  // fix to allow HTTPS connections with incorrect certificates
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

  curl_setopt ($ch, CURLOPT_URL,$onlineresource);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  curl_setopt ($ch, CURLOPT_ENCODING , "gzip, deflate");

  $file_contents = curl_exec($ch);
  $lines = array();
  $lines = explode("\n", $file_contents);
  if(!($response = $lines)) {
    echo "Unable to retrieve file '$service_request'";
  $response = implode("",$response);
  return $response;
  • 1
    What do you see in Firebug? Are you sure that your proxy is working? – Devdatta Tengshe Jun 24 '13 at 8:24
  • I got an XML Parsing error under the Net> XHR> XML tab. XML Parsing Error: no element found Location: moz-nullprincipal:{b5d7cfc7-e168-47e7-bf0f-6911bd193be4} Line Number 2, Column 1: ^ – K Hsueh Jun 24 '13 at 22:53
  • I also set up a web server on my local machine for testing. The WMSGetFeatureInfo function is working properly there. I am not sure why I receive that error when running on amazon. – K Hsueh Jun 24 '13 at 23:16
  • The problem is definetly within your proxy. What happens when you try: http://my_site.com/proxy.php?url=http://my_site.com:8088/geoserver/web – Devdatta Tengshe Jun 25 '13 at 2:50
  • I got the following error message: "This page contains the following errors: error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error." – K Hsueh Jun 25 '13 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.