代码之家  ›  专栏  ›  技术社区  ›  LucyTurtle

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

  •  0
  • LucyTurtle  · 技术社区  · 6 年前

    我需要对使用像素发送服务器到服务器的信息有一些了解。我们使用validclick,他们说他们的信标必须发送到1x1透明图像。从我所做的一切来看,我找不到使用1x1 gif接收数据的基本“操作方法”。

    我现在拥有的是一个。php文件和我的gif,然后我的脚本读取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的末尾。因此,当我使用测试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和我的图像在一起。我认为页面只能包含图像。但是,如果我将其从页面中删除,我不知道如何从信标接收数据。

    1 回复  |  直到 6 年前
        1
  •  0
  •   LucyTurtle    6 年前

    希望这段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==');