[GIS] How to configure WFS layer with OpenLayers in PHP WampServer

openlayers-2PHPPROXYwfs

I have a problem to display WFS layer outside the GeoServer. My code working fine in GeoServer, but when I tried my code in WampServer(PHP), only WMS layer is being to displayed.

I've gone through many tutorial and stack overflow queries related to adding WFS layer in OpenLayers but nothing working in my case… I have also tried proxy.cgi scripts to allow proxy call to GeoServer, but it not works. Is CGI proxy script can be used only with Python or it can be used with PHP as well?

Best Answer

You need a PHP proxy. This is a simple proxy.php script. It will be completely open, and you might want to lock it down.

<?php
 $ch = curl_init($_GET['url']);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $output = curl_exec($ch);
 curl_close($ch);
 echo $output;
?>

In your OpenLayers JavaScript config point to you proxy.php script with the following:

OpenLayers.ProxyHost = "proxy.php?url=";

Source: http://osgeo-org.1560.n6.nabble.com/proxy-and-apache-tp3912603p3912617.html