-1

I've been always curious how would badges be made (like these in Stackoverflow) with PHP.

I was thinking about 3 tables for storaging the data, but how, when & why should I do the checks for earning badges.

For example: badge - first post or badge - 2000 posts.

I'm a beginner in thinking like a programmer and i'm looking for best practices and so.

Joe Doyle
  • 6,363
  • 3
  • 42
  • 45
Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103

2 Answers2

3

There are basically two ways:

  • Check badge criteria whenever an action occurs that might result in a user receiving a badge. This is easy if you only have badges like "first post", "x posts" but nothing like "post viewed by x people"
  • Have a cronjob performing the checks. This is useful for things like "viewed by x people" since you don't have to perform all the checks whenever someone views something.

Of course you can also mix both solutions.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
1

In many hosted systems, you won't be able to run cron jobs. Then I would create a checkBadges section in my PHP, so I can update badge information when user loads a page. You have to be careful and keep the code small, so you wont get performance issues. I.e. Only check for badges in reach and not those completed.

Bjørne Malmanger
  • 1,457
  • 10
  • 11