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

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


use your proxy to request the GetCapabilities and see, if it works


If it works, then it seem to be some misconfiguration with the map and the
WFS layer.


-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at
[mailto:openlayers-users-bounces at] Im Auftrag von Gabriele
Gesendet: Mittwoch, 14. September 2011 13:22
An: users at
Betreff: [OpenLayers-Users] Problems with setting up a proxy.php


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
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 ""

Firefox shows:
XML-Verarbeitungsfehler: Kein Element gefunden
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=
"";' 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({
			    featureType: "gis_elemente",
			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
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",
				layers: 'MMPbasic:gis_elemente',
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.


the proxy.php:

 	// Taken from Community Mapbuilder svn trunk
 	// on 10 September 2008
 	License: LGPL as per:
 	$Id: proxy.php,v 1.2 2008-09-10 14:21:44 tkralidi Exp $
	$Name:  $

	// Description:
 	// Script to redirect the request
 	// to http://someUrl .
	// This script can be used to circumvent javascript's security
	// 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
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;


View this message in context:
Sent from the OpenLayers Users mailing list archive at
Users mailing list
Users at

More information about the Users mailing list