Accessing the SilverWebservice using PHP

When writing the post on how to integrate Sumatra in an Essence Portal, I already suspected questions about this. And yes, The question I expected was asked rather quickly after that post went online. Some people noticed that we have a report that shows statistics on our website traffic. So, how do we gather the data for these statistics?

We have the Channels and ChannelFacts

In our own database, we have tables for Channels. Every website is classified as a separate Channel, as are our Campaigns. For each Channel, we can record what's happening in our ChannelFacts table. Using these tables, we have extracted 2 BusinessControllers in our Portal.

So far, that's just pretty basic and straight forward stuff. So, how do we fill the ChannelFacts table?

Accessing the SilverWebservice using PHP

From every webpage we have, we use the SilverWebservice to monitor webpage activity. By sending a Webservice Request to the SilverWebservice, containing the information we want. Most C# developers are familiar in doing that, and there are more than enough code samples you can find online. 

But we also have some PHP webpages, and we found that PHP programmers are less familiar with Webservices. So here is a code snippet from one of our own pages, showing how to send a Request (using cURL) to the SilverWebservice on every page load.

Do keep in mind that we are not experienced PHP programmers, but we are sure you will appreciate the example. More information about the SilverWebservice can be found in this document.

Code snippet

$url = "";

$input_xml = '<SilverBusinessController name="ChannelFact">
<Request consumerAuthenticationToken="" consumerRefreshAuthenticationToken="" consumerUserAuthenticationToken="">
<BusinessEntity name="ChannelFact" id="">
<Property propertyName="ChannelFactTypeID" propertyValue="A0F45D1C-B8D6-46E5-AF7F-C51A94D52F70" />
<Property propertyName="ChannelID" propertyValue="662c5881-adeb-43b3-9b2f-cf3da807c161" />
<Property propertyName="RawURL" propertyValue="RAW_URL" />
<Property propertyName="Referrer" propertyValue="REFERRER" />
<Property propertyName="VisitorIP" propertyValue="" />
<Property propertyName="UserAgent" propertyValue="USER_AGENT" />
<Property propertyName="Description" propertyValue="RAW_URL" />
<Controller name="ChannelFact">
<BusinessEntity name="ChannelFact" id=""></BusinessEntity>

$input_xml = str_replace("", $_SERVER['REMOTE_ADDR'], $input_xml);
$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$input_xml = str_replace("RAW_URL", $actual_link, $input_xml);
$input_xml = str_replace("REFERRER", $_SERVER['HTTP_REFERER'], $input_xml);
$input_xml = str_replace("USER_AGENT", $_SERVER['HTTP_USER_AGENT'], $input_xml);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input_xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 9800);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
$input_xml = curl_exec($ch);
print curl_error($ch);

if (curl_errno($ch))
print curl_error($ch);