是否可以计算图像或闪存文件在我的服务器上被查看的次数



我想在我朋友的一些网站上放置我的网站的广告,我想看看每个网站查看这些广告的次数。我正在寻找执行此操作的解决方案。

Apache 是否记录从我的服务器请求文件的次数,或者是否可以创建一个 htaccess 文件来执行此操作。我不知道我应该从哪里开始,所以如果你们知道,请将我重定向到正确的地方。

创建一个显示如下图像的 php 文件:

    if(file_exists($path))
    { 
        header('Content-Length: '.filesize($path));
        header('Content-Type: image/jpg');
        header('Content-Disposition: inline; filename="'.$path.'";');
        echo file_get_contents($path);
        exit;
    }

现在,您可以在图像发布之前添加PHP代码,并且可以跟踪视图。只要确保在 header() 调用之前没有发布任何内容即可。甚至没有空格或 HTML 标记(否则它会破坏图像)。

您可以使用 .htaccess 显示带有.jpg结尾的文件。

上一篇文章的建议非常好,要使其完整,请这样做:

在您的服务器上创建一个PHP文件,输出您的广告并将您的广告放置在您的朋友页面中,例如图像:

<img src="http://yourdomain.com/output.php?type=jpg&id=X">

或用于闪光灯

<embed src="http://yourdomain.com/output.php?type=swf&id=X" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">
</embed>

在PHP文件中,您可以检查ID以加载匹配的广告(您应该有一个数据库或CSV文件,其中包含不同添加的列表。

<?php
  if(isset($_GET["id"]))
  {
    $list = load_addlist_from_db(); // <----- here you should write you own function to load your list of possible adds e.g. as array
    if(array_key_exists($_GET["id"], $list))
    {
      $filename = $list[$_GET["id"]];
      if(is_readable($filename))
      {
        header("Content-Length: ".filesize($filename));
        // set the last modification time of downloadfile or phpscript, whatever is newer
        $modtime_str = gmdate("D, d M Y H:i:s", max(filemtime($filename),getlastmod())) . " GMT";
        header("Last-Modified: ". $modtime_str);
        switch($_GET["type"])
        {
          case "jpg":
          case "jpeg": 
          {
            header("Content-Type: image/jpg"); // coul also be "image/png", "image/gif" depending on what file you like to output
          }
          case "swf":
          {
            header("Content-Type: application/x-shockwave-flash");
          }
        }
/*
 * here you can count the request to this add (or use the bbclone code below)
 * check $_SERVER['HTTP_REFERER'] to get information from what page the file was loaded 
 */
        readfile($filename);
      }
      else $file_not_found = true;
    }
    else $file_not_found = true;
  }
  else $file_not_found = true;
  if($file_not_found)
  {
    // that tells the browser, that the requestes file doas not exist
    header("Status: 404 Not Found",true,404);
  }
?>
在此文件中,

您可以在自己的数据库/文件中计算您的请求,或者您使用BBClone,甚至可以计算访问者的浏览器和操作系统。

您可以在输出中包含 BBclone.php如下所示:

define("_BBC_PAGE_NAME",basename($filename));
define("_BBCLONE_DIR", $_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR."bbclone");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
include_once(COUNTER);

您可以放置如下所示的图像像素,并将它们包含在显示Flash文件的文件中:

<img src="http://yourdomain.com/flashcount.php" style="display:none" />

flashcount.php中,您可以使用$_SERVER referrer获取执行域的信息,并将其单击和服务器信息存储在某个数据库表上。

最新更新