Pionads Helpfiles: Php Rest Client

Home

Php Rest Client

PHP Rest client

Example PHP Rest client implementation (fill the host, adspace and key with the settings from your adspace)


<?php
error_reporting(E_ALL);

// Add the url to your pionads server here (e.g. http://ads.mydomain.com:8732)
$pionadsHost = "";
// Add the adspace id here (format as dcfe8a46-0133-4fb1-965f-39e42336cab6)
$pionadsAdSpaceId = "";
// Add the API key here
$pionadsApiKey = "";
// Create a hash which allows pionads to recognize the visitor
$pionadsIpHash = $_SERVER['REMOTE_ADDR'];

$restUrl = $pionadsHost . "/rest/publish-adspace/" . $pionadsAdSpaceId . "?key=" . $pionadsApiKey . "&clientHash=" . pionadsIpHash;

$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"X-Real-IP: " . $_SERVER['REMOTE_ADDR']  . "\r\n" .
              "X-User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n" .
              "Cache-Control: no-cache" . "\r\n"
  )
);

$context = stream_context_create($opts);
$rawResponse = file_get_contents($restUrl, false, $context);

$xmlDoc = simplexml_load_string(trim($rawResponse));

?>
<a href="<?php echo $xmlDoc->ad->clickurl; ?>" target="_blank">
	<img src="<?php echo $xmlDoc->ad->img->src; ?>" />
</a>


 
[Please implement an object class template for: core.managers.ResourceManager/resourcemanager_js]