Tag Archives: php

Get request headers sent by client in PHP

A nice little function I found posted by “lazynitwit” on BlueHost forums:

function getHeaders()
{
$headers = array();
foreach ($_SERVER as $k => $v)
{
if (substr($k, 0, 5) == "HTTP_")
{
$k = str_replace('_', ' ', substr($k, 5));
$k = str_replace(' ', '-', ucwords(strtolower($k)));
$headers[$k] = $v;
}
}
return $headers;
}

The PHP function getallheaders() only works on Apache, and only if Apache has been installed as a module.

It turns out that this information is within the $_SERVER global variable, and can be parsed out.

This code is useful if, for instance, you want to differentiate between user browser requests and requests made through AJAX. Some of the JavaScript frameworks (jQuery, Prototype, YUI, MooTools) send a special header,

X-Requested-With: XMLHttpRequest

whenever a request is made. I have put this to use in my phpFreeChat chat box to allow channels to be specified in the URL as GET parameters.

via request headers php – bluehostforum.com.

VN:F [1.9.22_1171]
Rating: 4.4/5 (12 votes cast)
VN:F [1.9.22_1171]
Rating: +5 (from 5 votes)

MapServer: Using Google Maps with PHP MapScript

Generating Google Maps tiles using MapServer is not completely intuitive. For static map applications, a new tile mode has recently been created for MapServer CGI mode ( http://mapserver.org/output/tile_mode.html ).

For more dynamic mapping applications, PHP MapScript is an ideal way execute this, as it only requires a very small static component (an initial map file, which won’t even be needed when MapServer 5.4 comes). Included is a short PHP example on how do go about doing this. The PROJ.4 projection parameters included are for the Google Maps mercator projection.

The sample code includes WGS84 to Google Maps mercator projection as well as the calculation of mercator extents from Google Maps tile indices.

This example has been extended from the previous iteration to include dynamic layer generation and POINT geometry feature symbols via image files. The $phplayers variable holds layer definitions that have been queried from a database table, obtained using the getLayersForSessionID($sessionID) function. The table includes layer table name, layer geometrytype layer geometry name, and a symbol definition for the layer. For point layers, this is an image file (ie. “image.gif”), and for polygon and line layers, this is a line color (255 0 0 for red).

Attached Files:

VN:F [1.9.22_1171]
Rating: 3.8/5 (4 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 2 votes)