Codeigniter openX XML-RPC

This method can be used if we want codeigniter to include and use openX ads using the XML-RPC invocation method.

function special_ad_xmlrpc() {

	$this->load->library('xmlrpc');

	$server_url = 'http://someadserver.com/www/delivery/axmlrpc.php';

	$this->xmlrpc->server($server_url, 80);

	$this->xmlrpc->method('openads.view');

	$aServerVars = array(
            'remote_addr'       => 'REMOTE_ADDR',
            'remote_host'       => 'REMOTE_HOST',

            // Declare headers used for ACLs:
            'request_uri'       => 'REQUEST_URI',
            'https'             => 'HTTPS',
            'server_name'       => 'SERVER_NAME',
            'http_host'         => 'HTTP_HOST',
            'accept_language'   => 'HTTP_ACCEPT_LANGUAGE',
            'referer'           => 'HTTP_REFERER',
            'user_agent'        => 'HTTP_USER_AGENT',

            // Declase headers used for proxy lookup:
            'via'               => 'HTTP_VIA',
            'forwarded'         => 'HTTP_FORWARDED',
            'forwarded_for'     => 'HTTP_FORWARDED_FOR',
            'x_forwarded'       => 'HTTP_X_FORWARDED',
            'x_forwarded_for'   => 'HTTP_X_FORWARDED_FOR',
            'client_ip'         => 'HTTP_CLIENT_IP'
        );

        // Create the environment array:
        $aRemoteInfo = array();
        foreach ($aServerVars as $xmlVar => $varName) {
            if (isset($_SERVER[$varName])) {
                $aRemoteInfo[$xmlVar] = $_SERVER[$varName];
            }
        }

	// Add cookies:
        $aRemoteInfo['cookies'] = array($_COOKIE, 'array');

	$request = array(
	    array($aRemoteInfo, 'struct'),
	    array('zone:269', 'string'),
	    array(0, 'int'),
	    array('', 'string'),
	    array('', 'string'),
	    array(FALSE, 'boolean'),
	    array(array(), 'array')
	);
	$this->xmlrpc->request($request);

	if ( ! $this->xmlrpc->send_request())
	{
	    return false;
	}
	else
	{
	    $response = $this->xmlrpc->display_response();
	    return $response;
	}
}

About this entry