AW: [OpenLayers-Users] Problems with setting up a proxy.php

Arnd Wippermann arnd.wippermann at web.de
Wed Sep 14 15:41:14 EDT 2011


Hi,

That's an explanation, that may help you to understand the need of a proxy

http://lists.osgeo.org/pipermail/openlayers-users//2009-February/010417.html
 
Arnd

-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Christian
Röttger
Gesendet: Mittwoch, 14. September 2011 16:26
An: openlayers-users at lists.osgeo.org
Betreff: Re: [OpenLayers-Users] Problems with setting up a proxy.php

Hi,

i have additional questions about proxy, do not understand it too.

do i have to include a proxy when i develop the code on my laptop,
connecting to my geoserver (other machine)? If yes, where do i have to
install it?

And do i have to include a proxy when i upload the html page to my server
and only connect to the geoserver on the same machine?

At the last case no proxy is needed, if i understood the wiki, or?

greets
christian


Am 14.09.2011 13:22, schrieb Gabriele Seitz:
> Hi,
>
> I have got problems, getting a proxy-server for using WFS running on 
> my linux-server. Geoserver is ok and serving WMS.
> I gave up on getting to run proxy.cgi, as described in 
> "http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyH
> ost", but in this forum found a hint on a proxy.php
>
> This is what I did (using firefox 6.0.2):
> I copied the proxy.php to a location on the server where I can call 
> ist by typing "http://sub.domain.com/proxy.php?url="
>
> Firefox shows:
> XML-Verarbeitungsfehler: Kein Element gefunden
> Adresse: http://sub.domain.com/proxy.php?url=
> Zeile Nr. 2, Spalte 1:
>
> (which is something like "XML-computing error. no element found, 
> adress http... line 2, column 1")
>
> In my script, that defines the WFS, I am using 'OpenLayers.ProxyHost= 
> "http://sub.domain.com/proxy.php?url=";' before defining a WFS-layer
>
> Definition of WFS like this:
>
> 		var pointlayer =new OpenLayers.Layer.Vector("WFS", {
> 			strategies: [new OpenLayers.Strategy.BBOX()],
> 			protocol: new OpenLayers.Protocol.WFS({
> 			    url:
"http://sub.domain.com/geoserver/MMPbasic/wfs",	
> 			    featureType: "gis_elemente",
> 			    featureNS:
"http://sub.domain.com/geoserver/MMPbasic"
> 			}),
> 			styleMap: new OpenLayers.StyleMap({
> 			    strokeWidth: 3,
> 			    strokeColor: "#333333"
> 			}),
> 		    });
>
> Firebug shows:
> XML-Verarbeitungsfehler: Kein Element gefunden Adresse:
> moz-nullprincipal:{ff05177f-b54a-42f3-a833-4eb51f10ca69} Zeile Nr. 1, 
> Spalte
> 1:
> which is basicly the same as above, except that it doesn't show the 
> adress but some mozilla-stuff.
>
> In DOM I find the layer, but no features in it.
>
> Definition of WMS from the same source is okay and shows correctly
> 		var flaglayer = new OpenLayers.Layer.WMS("WMS",
> 			"http://sub.domain.com/geoserver/MMPbasic/wms",
> 			{
> 				layers: 'MMPbasic:gis_elemente',
> 				transparent:true
> 			}
> 		);
> CetCapabilities-Request
> http://sub.domain.com/geoserver/wfs?service=wfs&version=1.1.0&request=
> GetCapabilities seems okay to me. I can see the requested featuretype.
>
> Is there something wrong with my code or with the Proxy. I give you 
> the code of proxy.php at the end.
>
> Thanks for helping.
>
> Gabriele
>
> the proxy.php:
>
> <?php
>   	
>   	// Taken from Community Mapbuilder svn trunk
>   	//
> http://svn.codehaus.org/mapbuilder/trunk/mapbuilder/server/php/proxy.php
>   	// on 10 September 2008
>   	
>   	/*
>   	License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
>   	$Id: proxy.php,v 1.2 2008-09-10 14:21:44 tkralidi Exp $
> 	$Name:  $
>   	*/
> 	
>
>
////////////////////////////////////////////////////////////////////////////
////
> 	// 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)){
>   	  $onlineresource=$_SERVER['HTTP_SERVERURL'];
> 	}else{
>   	  $onlineresource=$_REQUEST['url'];
>   	}
>   	$parsed = parse_url($onlineresource);
>   	$host = @$parsed["host"];
>   	$path = @$parsed["path"] . "?" . @$parsed["query"];
>   	if(empty($host)) {
>   	  $host = "localhost";
>   	}
>   	$port = @$parsed['port'];
>   	if(empty($port)){
>   	  $port="80";
>   	}
>   	$contenttype = @$_REQUEST['contenttype'];
>   	if(empty($contenttype)) {
>   	  $contenttype = "text/xml";
>   	}
>   	$data = @$GLOBALS["HTTP_RAW_POST_DATA"];
>   	// define content type
>   	header("Content-type: " . $contenttype);
>   	
>   	if(empty($data)) {
>   	  $result = send_request();
>   	}
>   	else {
>   	  // post XML
>   	  $posting = new HTTP_Client($host, $port, $data);
>   	  $posting->set_path($path);
>   	  $result = $posting->send_request();
>   	}
>
>   	// strip leading text from result and output result
>   	$len=strlen($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,
>   	      $this->port,
> 	      $this->errno,
>   	      $this->errstr,
>   	      $this->timeout
>   	      );
>   	    if(!$this->socket)
>   	      return false;
>   	    else
>   	      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 = "";
>   	    fwrite($this->socket,
>   	      "POST $this->path HTTP/1.0\r\n".
>   	      "Host:$this->host\r\n".
> 	      "User-Agent: $this->agent_name\r\n".
>   	      "Content-Type: application/xml\r\n".
> 	      "Content-Length: ".strlen($data).
> 	      "\r\n".
> 	      "\r\n".$data.
>   	      "\r\n"
>   	    );
> 	
>   	    while(!feof($this->socket))
> 	      $this->buf .= fgets($this->socket, 2048);
>   	      $this->close();
>   	      return $this->buf;
>   	  }
>   	
>   	
>   	  function close() {
>   	    fclose($this->socket);
>   	  }
> 	}
>   	
> 	
>   	
>   	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);
>   	  curl_close($ch);
> 	  $lines = array();
>   	  $lines = explode("\n", $file_contents);
>   	  if(!($response = $lines)) {
>   	    echo "Unable to retrieve file '$service_request'";
>   	  }
>   	  $response = implode("",$response);
>   	  return $response;
>   	}
>
>   	?>
>
>
> --
> View this message in context: 
> http://osgeo-org.1803224.n2.nabble.com/Problems-with-setting-up-a-prox
> y-php-tp6792124p6792124.html Sent from the OpenLayers Users mailing 
> list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users





More information about the Users mailing list