Adsense Mobile Hack:任何方法都可以找出PHP脚本中最后返回的内容


Adsense Mobile Hack: Any way to find out what was the last thing echo'd in a PHP script?

大家都知道,我们不允许修改Adsense PHP脚本,因为它违反了TOS。

我工作的一个网站是手机,Adsense移动广告创建设备类型"所有手机"没有给你选择"替代广告"出于一些奇怪的原因,但超过20%的印象没有显示广告"(不匹配的广告请求)"。

没有Adsense支持,我在网上找不到任何解决这个问题的方法。

然而,我注意到,当没有Adsense的移动广告显示,谷歌只是回声的<!-- google_afm -->。因此,我所需要做的是强制显示一个替代广告是找出谷歌回声的<!-- google_afm -->,然后只是显示替代自己。

现在,这将是非常容易做到的,如果我可以改变Adsense PHP代码在以下行:

echo fread($google_ad_handle, 8192);

但是,这将违反服务条款,我将冒着被封号的风险。

因为我正在做这个脚本的include,无论如何都要确定在PHP中什么是脚本的最后一件事?

如果没有,那么你是否可以建议我展示其他广告,这样我就不会浪费超过20%的印象?

<?php
  ob_start();
  include "adsense_script.php";
  $output = ob_get_clean();
  if (substr($output,-19) == '<!-- google_afm -->') {
    // display alternate here
  }
?>

可以使用输出缓冲控制。例如:

ob_start();
include("/path/to/script.php");
$data = ob_get_contents();
ob_end_clean();

您可以使用输出缓冲,例如include:

<?php
    /**
     * include_get_contents
     *
     * include a file and return it's output
     *
     * @param string $path filename of include
     * @return string
     */
    function include_get_contents($path)
    {
        ob_start();
        include($path);
        return ob_get_clean();
    }