1.add folder in {documnet_root}/www/{yourname}/
ex. adserver/json/
2.add php file ex.api.php
3.add content like this
//xid param from your url like {yourdoamin}/www/json/api.php?xid=10
//xid eq zoneid
//set your AD like banner type
$_GET['zoneid'] =$_GET['xid'];
// Require the initialisation file
require_once '../../init-delivery.php';
// Required files
require_once MAX_PATH . '/lib/max/Delivery/adSelect.php';
require_once MAX_PATH . '/lib/max/Delivery/flash.php';
// No Caching
MAX_commonSetNoCacheHeaders();
//Register any script specific input variables
MAX_commonRegisterGlobalsArray(array('refresh', 'resize', 'rewrite', 'n'));
// Initialise any afr.php specific variables
if (!isset($rewrite)) $rewrite = 1;
if (!isset($refresh)) $refresh = 0;
if (!isset($resize)) $resize = 0;
// Get the banner
$banner = MAX_adSelect($what, $campaignid, $target, $source, $withtext, $charset, $context, true, $ct0, $loc, $referer);
// Send cookie if needed
if (!empty($n)) {
if (!empty($banner['html'])) {
// Send bannerid headers
$cookie = array();
$cookie[$conf['var']['adId']] = $banner['bannerid'];
// Send zoneid headers
if ($zoneid != 0) {
$cookie[$conf['var']['zoneId']] = $zoneid;
}
// Send source headers
if (!empty($source)) {
$cookie[$conf['var']['channel']] = $source;
}
// Set the cookie
MAX_cookieAdd($conf['var']['vars'] . "[$n]", json_encode($cookie, JSON_UNESCAPED_SLASHES));
} else {
MAX_cookieUnset($conf['var']['vars'] . "[$n]");
}
}
MAX_cookieFlush();
MAX_commonSendContentTypeHeader('text/html', $charset);
// Rewrite targets in HTML code to make sure they are
// local to the parent and not local to the iframe
if (isset($rewrite) && $rewrite == 1) {
$banner['html'] = preg_replace('#target\s*=\s*([\'"])_parent\1#i', "target='_top'", $banner['html']);
$banner['html'] = preg_replace('#target\s*=\s*([\'"])_self\1#i', "target='_parent'", $banner['html']);
}
// Build HTML
$outputHtml = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n";
$outputHtml .= "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n";
$outputHtml .= "<head>\n";
$outputHtml .= "<title>".(!empty($banner['alt']) ? $banner['alt'] : 'Advertisement')."</title>\n";
// Include the FlashObject script if required
if (isset($banner['contenttype']) && $banner['contenttype'] == 'swf') {
$outputHtml .= MAX_flashGetFlashObjectExternal();
}
// Add refresh meta tag if $refresh is set and numeric
if (isset($refresh) && is_numeric($refresh) && $refresh > 0) {
$dest = MAX_commonGetDeliveryUrl($conf['file']['frame']).'?'.$_SERVER['QUERY_STRING'];
parse_str($_SERVER['QUERY_STRING'], $qs);
$dest .= (!array_key_exists('loc', $qs)) ? "&loc=" . urlencode($loc) : '';
$refresh = (int)$refresh;
// JS needs to be escaped twice: the setTimeout argument is evaluated at runtime
$jsDest = addcslashes(addcslashes($dest, "\0..\37\"\\"), "'\\");
$htmlDest = htmlspecialchars($dest, ENT_QUOTES);
// Try to use JS location.replace since browsers deal with this and history much better than meta-refresh
$outputHtml .= "
<script type='text/javascript'><!--// <![CDATA[
setTimeout('window.location.replace(\"{$jsDest}\")', " . ($refresh * 1000) . ");
// ]]> --></script><noscript><meta http-equiv='refresh' content='".$refresh.";url={$htmlDest}'></noscript>
";
}
if (isset($resize) && $resize == 1) {
// If no banner found, use 0 as width and height
$bannerWidth = empty($banner['width']) ? 0 : $banner['width'];
$bannerHeight = empty($banner['height']) ? 0 : $banner['height'];
$outputHtml .= "<script type='text/javascript'>\n";
$outputHtml .= "<!--// <![CDATA[ \n";
$outputHtml .= "\tfunction MAX_adjustframe(frame) {\n";
$outputHtml .= "\t\tif (document.all) {\n";
$outputHtml .= "\t\t\tparent.document.all[frame.name].width = ".$bannerWidth.";\n";
$outputHtml .= "\t\t\tparent.document.all[frame.name].height = ".$bannerHeight.";\n";
$outputHtml .= "\t\t}\n";
$outputHtml .= "\t\telse if (document.getElementById) {\n";
$outputHtml .= "\t\t\tparent.document.getElementById(frame.name).width = ".$bannerWidth.";\n";
$outputHtml .= "\t\t\tparent.document.getElementById(frame.name).height = ".$bannerHeight.";\n";
$outputHtml .= "\t\t}\n";
$outputHtml .= "\t}\n";
$outputHtml .= "// ]]> -->\n";
$outputHtml .= "</script>\n";
}
$outputHtml .= "<style type='text/css'>\n";
$outputHtml .= "body {margin:0; height:100%; background-color:transparent; width:100%; text-align:center;}\n";
$outputHtml .= "</style>\n";
$outputHtml .= "</head>\n";
$jsonArr['html'] = ($banner['html']);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials true');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept,token,Access-Token');
header('Access-Control-Max-Age: 1728000');
header("Content-type: application/json; charset=utf-8");
echo json_encode($jsonArr);
exit;