Simple PHP request
Most users of the TBXDS service receive an example requestor
script written in VBScript. However, on non-Microsoft platforms
other scripting languages are needed, and PHP is one scripting
language available on almost all web platforms.
Do make sure you don't use this script on a publicly accessible
page!
<?
/*
* --------------------------------------------------------------------
* File: tbxds-request.php
* Purpose: Example TBXDS request script
* Author: Joost Roelandt (joost.roelandt@persgroep.be)
* Revision: 2006/09/21
* --------------------------------------------------------------------
* NOTES
*
* You can start this script by either running tbxds-request.php
* directly, of by using php.exe from the command line.
*
* This script is intended to show you the method of sending
* a TBXDS query to a TBXDS server. It is not intended to give
* a blue print for programs using the TBXDS, and therefore
* the script doesn't process the received result, but merely
* dumps it to the browser.
* --------------------------------------------------------------------
*
*/
define('FILENAME_SAVE' , 'tbxds-data.xml');
define('FILENAME_REQUEST' , 'tbxds-request.xml');
define('SERVER_NAME' , 'ws.vwdservices.com');
define('TBXDS' , '/tbxds/tbxds.asp');
function http_post(&$request)
{
$fp = fsockopen(SERVER_NAME, 80, $errno, $errstr, 30);
if (!$fp) {
echo "Connect: $errno, $errstr\n";
return false;
}
$mesg
= "POST ".TBXDS." HTTP/1.0\r\n"
. "Host: ".SERVER_NAME."\r\n"
. "User-Agent: PHP Script\r\n"
. "Content-Type: text/xml\r\n"
. "Content-Length: ".strlen($request)."\r\n"
. "Connection: close\r\n"
. "\r\n";
fwrite($fp, $mesg);
fwrite($fp, $request);
$res = "";
$body = false;
while (!feof($fp))
{
$tmp = fgets($fp, 512);
if ($body)
$res .= $tmp;
else {
$tmp=trim($tmp);
if (empty($tmp))
$body = true;
}
}
fclose($fp);
return $res;
}
$request = file_get_contents(FILENAME_REQUEST);
if ($request===false)
{
echo "Could not read ".FILENAME_REQUEST."\n";
exit;
}
$data = http_post($request);
if ($data===false)
{
echo "Could not read data from ".SERVER_NAME."\n";
exit;
}
header("Content-Type: text/xml");
echo $data;
?>