PHP Wrapper to hide mapfile location

Pagurek,Debbie [NCR] Debbie.Pagurek at EC.GC.CA
Fri Oct 7 09:31:39 EDT 2005


As a follow on to this post - we found that our first attempt at a PHP
wrapper to use instead of an .asp wrapper wasn't adequate. Below is the
PHP code that we are now testing. It covers responses for WMS and WFS
requests. It would be great if others on the list could test this out or
comment on the method. Any suggestions?


<?

// Full path to your mapserv with its map file.
//======================================================================
=========================================================

$strURL =
"http://theserver/cgi-bin/mapserv.exe?map=c:\ms4w\apps\map\water1_en.map
&";
//======================================================================
=========================================================

function buildQueryString($theArray)
{
foreach($theArray as $key=> $value)
	{
	$finalString.= "&$key=".urlencode($value);
	}
return $finalString;
}

if($_GET)
	{
	$strRequest 				= $_GET;
	$theRequest 				= $_GET["request"];
	$theMode					= $_GET["mode"];
	$theFormat  				= $_GET["format"];
	$theExceptionFormat 		= $_GET["exceptions"];
	$theGetFeatureInfoFormat	= $_POST["info_format"];	
	}
	else
	{
	$strRequest 					= $_POST;
	$theRequest 					=
$_POST["request"];
	$theMode						=
$_GET["mode"];
	$theFormat  					=
$_POST["format"];
	$theExceptionFormat 			= $_POST["exceptions"];
	$theGetFeatureInfoFormat 		= $_POST["info_format"];
	}
//
------------------------------------------------------------------------
------------------
if(!$theExceptionFormat)
	{
	$theExceptionFormat = "application/vnd.ogc.se_xml"; // default
format for exceptions
	}
if(!$theGetFeatureInfoFormat )
	{
	$theGetFeatureInfoFormat  = "application/vnd.ogc.gml"; //
default format for getFeatureInfo
	}
if(!$theFormat)
	{
	$theFormat = "image/gif"; // default to image/gif mime type
	}

// if the request is for mode=legend and not request=??? then check
if(strtoupper($theMode) == "LEGEND")
	{
	$theRequest = "SHOWIMAGE"; // show default image/gif
	}

$handle = fopen($strURL.buildQueryString($strRequest), "r");
$contents = '';
if($handle) // if server url is alive and kicking 
	{
 	while (!feof($handle)) // not at end of file. 
		{
	   $contents .= fread($handle, 8192);
	   if(stristr($contents,'ServiceExceptionReport')) // look for
ServiceExceptionReport in content for WMS Exception
	   		{
			$theRequest = "FOUNDEXCEPTION";
			}
	  	}
	fclose($handle);
}

switch(strtoupper($theRequest))
	{
	case "FOUNDEXCEPTION":
		{
		header('Content-Type: '.$theExceptionFormat.';');
		break;
		}		
	case "GETMAP":
		{
		header('Content-Type: '.$theFormat.';');
		break;
		}
	case "GETLEGENDGRAPHIC":
		{
		header('Content-Type: '.$theFormat.';');
		break;
		}
	case "GETFEATUREINFO"; 
		{
		header('Content-Type: '.$theGetFeatureInfoFormat.';');
		break;
		}
	case "GETFEATURE"; 
		{
		header('Content-Type: application/vnd.ogc.gml;');
		break;
		}		
	case "GETCAPABILITIES";
		{
		header('Content-Type: application/vnd.ogc.wms_xml;');
		break;
		}
	case "DESCRIBELAYER";
		{
		header('Content-Type: text/xml;');
		break;
		}
	case "SHOWIMAGE":
		{
		header('Content-Type: '.$theFormat.';');
		break;
		}			
	default:
		{
		header('Content-Type: text/plain;');
		}
	}
echo $contents;
?>

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Pagurek,Debbie [NCR]
Sent: Thursday, September 29, 2005 3:59 PM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] PHP Wrapper to hide mapfile location


Hi all,
A developer at my office has written the following PHP wrapper to hide
the location of mapfiles. I have seen .asp scripts to do this but no PHP
scripts have been brought to attention until now so I thought I would
present this to the community for feedback. 

I have tested this briefly.
Any comments anyone?

D. Pagurek

<?
function buildQueryString($theArray)
{
foreach($theArray as $key=> $value)
	{
	$finalString.= "&$key=".urlencode($value);
	}
return $finalString;
}

if($_GET)
	{
	$strRequest = $_GET;
	}
	else
	{
	$strRequest = $_POST;
	}

$strURL =
"http://theserver/cgi-bin/mapserv.exe?map=C:\ms4w\apps\chameleon\map\tes
t.map&".buildQueryString($strRequest);

ini_set('user_agent','MSIE 4\.0b2;'); // fake a browser request. $handle
= fopen($strURL, "r"); $contents = '';
if($handle)
	{
 	while (!feof($handle))
		{
	   $contents .= fread($handle, 8192);
 		}
	fclose($handle);
}
echo $contents;

?>



More information about the mapserver-users mailing list