1

对于我网站上的每个广告,我想要一个显示其查看次数的框(类似于此网站)。

如何获取广告的页面浏览量?有没有在 PHP 中执行此操作的函数?

4

1 回答 1

4

Well, no there is no function that does this magically : you'll have to do a bit of work -- not that hard, though ;-)

There are two possible things you can count.


For the first one, number of times an ad is displayed, the basic idea is :

  • Your are displaying an add -- you already know how to do that
  • When displaying it, you'll update a counter, probably in your database :
    • Your SQL query will look like update ad_counters set counter = counter + 1 where ad_id = 123
    • 123 being replaced by the identifier of your ad, of course
  • And, when displaying the ad, you'll have to select that counter, and display it alongside the ad.


For the second one, number of times an ad is clicked, the basic idea is generally :

  • Not have the ad be a direct link to the page of the product
  • Instead, the link of the ad will look like http://yoursite.com/ad.php?id=123
  • And, when someone load that page, it will :
    • increment the counter of clicks : update ad_clicks_counter set counter = counter + 1 where ad_id = 123
    • redirect the user to the real page of the ad, or display it directly.

In fact, this is precisely what's done on SO :

  • An ad has a link such as http://ads.stackoverflow.com/a.aspx?Task=Click&ZoneID=4&CampaignID=785&AdvertiserID=161&BannerID=1123&SiteID=1&RandomNumber=384213225&Keywords=php%2ccounter%2cx-user-highrep%2cx-user-registered
  • And when you click on it, you are redirected to the real page of the ad, which can be such as http://www.xpolog.com/home/solutions/landing.jsp


Of course, those two counters can be in the same table -- or even in the table in which you have the list of all ads :-)

于 2010-04-07T21:11:27.797 回答