dpswo40440
dpswo40440
2013-05-31 08:25

ajax要求加载不在每个浏览器中运行的广告

已采纳

I have this ajax function to show a nivo slider based overlay with some images. I want to load the ads for every page, but only once per hour (so the ads pop up on the first visit, and then an hour later when you refresh). This function works in Chrome, IE, but doesn't work in Firefox for some reason, I have to refresh again in FF or get to a subpage for the ads to load: The function:

session_start();

require_once dirname(__FILE__) . '/../../admin/lib/config/config.inc.php';

$_SESSION['last_refresh'] = date("d-m-Y H:i:s");

$diff = strtotime($_SESSION['last_refresh']) -  strtotime($_SESSION['ad_datetime']);


 if(empty($_SESSION['ad_datetime'])) {
     $c = 1;
     $_SESSION['ad_datetime'] = date("d-m-Y H:i:s");
 } else {
     if($diff > 3600) {
        $c = 1;
        $_SESSION['ad_datetime'] = date("d-m-Y H:i:s");
     } else {
        $c = 0;
     }
 }


echo $c;

The $c = 1; is the response for the javascript file to load the ad. If the response is 0 it does nothing.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douxun4860 douxun4860 8年前

    Try changing your code like this

    if(empty($_SESSION['ad_datetime']) || $diff > 3600) {
         $c = 1;
         $_SESSION['ad_datetime'] = date("d-m-Y H:i:s");
     } else {
            $c = 0;
     }
    
    点赞 评论 复制链接分享

为你推荐