如何使用展示信标读取服务器呼叫数据(像素)



我需要对使用像素发送服务器到服务器的信息有一定的了解。我们使用validclick,他们说他们的信标必须发送到1x1透明图像。从我所做的所有外观中,我找不到有关使用 1x1 gif 接收数据的基本"方法"。

我现在有一个带有我的 gif 的 .php 文件,然后是我的脚本,用于从 URL 读取查询字符串并将其插入我们的数据库。

<?php
header('Content-Type: image/png');
echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=');

$conversion = $_SERVER['QUERY_STRING'];
$info = explode("&", $conversion);
$variables = array('id' => '', 'ts' => '', 'slotid' => '', 'q' => '', 'u' => '', 'ty' => '', 'nq' => '', 'nr' => '');
foreach ($info as $i) {
$temp = explode("=", $i);
$variables[$temp[0]] = $temp[1];
}
// Connect to the database
try {
// Info to connect to the database
$servername = "****";
$dbusername = "****";
$password = "****";
$dbname = "****";
// To connect to the database please
$conn = new mysqli($servername, $dbusername, $password, $dbname);
if ($conn->connect_error) {
die('Connect Error (' . $conn->connect_errno . ') ' . $conn->connect_error);
}
} catch (mysqli_sql_exception $e) { 
throw $e;
}
$variables['ts'] = str_replace("%", " ", $variables['ts']);
echo $variables['ts'];
$insert = "INSERT INTO validclickimpressions (id, ts, slotid, q, u, ty, nq, nr) " . 
"VALUES ('" . $variables['id'] . "', '" .
$variables['ts'] . "', '" .
$variables['slotid'] . "', '" .
$variables['q'] . "', '" .
$variables['u'] . "', '" .
$variables['ty'] . "', '" .
$variables['nq'] . "', '" .
$variables['nr'] . "')";
if(!$conn->query($insert)){
die('There was an error running the query "' . $insert . '" [' . $conn->error . ']');
}
$conn -> close;
?>

我想我只是缺少一些关于这些信标如何工作的基金会金属理解. validclick应该向此URL发送信息,并将这些变量附加到URL的末尾。因此,当我使用测试网址(例如:http://www.mywebsite.com/beacon_url/impression_beacon.php?id=1234&ts=2018-01-12%14:44:30&slotid=1234&q=1234&u=1234&ty=1234&nq=1234&nr=1234)访问时,这很有效,但是当我们收到展示次数时,似乎没有将数据插入我们的表格中。


编辑:我相信我的问题是我的php与我的图像有关。我认为页面只能包含图像。但是,如果我从页面中删除数据,我不知道如何从信标接收数据.

希望这个 php 代码能帮助任何试图在未来设置印象信标的人.此代码适用于 Inuvo。

/*
* YPA Impression BEACON END POINT
*/
// *** lowercase all param names ***
$_REQUEST = array_change_key_case($_REQUEST);
// Default impression args
$id = isset($_REQUEST['id']) ?  $_REQUEST['id'] : null; //  = coresponding impression ID
$ts = isset($_REQUEST['ts']) ?  $_REQUEST['ts'] : null; //  = unix timestamp of impression
$slotid = isset($_REQUEST['slotid']) ?  $_REQUEST['slotid'] : null; //  = location in page
$q = isset($_REQUEST['q']) ?  $_REQUEST['q'] : null; // = keyword
$u = isset($_REQUEST['u']) ?  $_REQUEST['u'] : null; // = landing page url
$ty = isset($_REQUEST['ty']) ?  $_REQUEST['ty'] : null; // = affid
$nq = isset($_REQUEST['nq']) ?  $_REQUEST['nq'] : null; // = number of ads requested for that ad unit / slot (New)
$nr = isset($_REQUEST['nr']) ?  $_REQUEST['nr'] : null; // = number of ads returned for that ad unit / slot (New)

// Your custom args defined in your YPA code block
// serveBeacon:"x=1&y=2&z=3", //string of key value pairs you want to hit this end point.
$x = isset($_REQUEST['x']) ?  $_REQUEST['x'] : null;
$y = isset($_REQUEST['y']) ?  $_REQUEST['y'] : null;
$z = isset($_REQUEST['z']) ?  $_REQUEST['z'] : null;
// write to your storage/db here

// Return image 1x1 gif content
header('Content-Type: image/gif');
echo base64_decode('R0lGODlhAQABAJAAAP8AAAAAACH5BAUQAAAALAAAAAABAAEAAAICBAEAOw==');

最新更新