Post Count Page?

We know you have an opinion on how things should be run around here. These are suggestions for the forums, and the website.This forum is not a place to ask for suggestions to your own coding (or otherwise) problems.

Moderator: General Moderators

Post Reply
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post Count Page?

Post by Jonah Bron »

Hello, world!

I'm working on a new website for myself. I'd like to have a cool little PHPDN badge for it, similar to the one on Stack Overflow. But, I figured that was too much to ask, because it would put a lot more load on the PHPDN server :( So I'm willing to settle for a compromise :wink: How about a page that I can call, that only prints out a user's post count? Like http://forums.devnetwork.net/postcount.php?u=314159265

Would this be easy for an admin to whip up?

Thanks!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Post Count Page?

Post by Jonah Bron »

Would it help if I threatened to scrape the site?

( :) not)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Post Count Page?

Post by Benjamin »

If you write it, I can tweak it for performance, then show it to the other mods for review.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Post Count Page?

Post by Jonah Bron »

Really appreciate it :)

I did a bit of research on the phpbb table schema, and came up with this. Boy, was I relieved to see that the phpbb_users table had a post count column, so I didn't have to count them :? . I'd love to test this, but I don't have a phpbb instance set up :( .

Code: Select all

<?php
if (!isset($_GET['u'])) {
    die('0');
}
$user = mysql_real_escape_string($_GET['u']);
$mysql = mysql_connect('host', 'user', 'pass', 'db');
$query = mysql_query('SELECT user_posts FROM phpbb_users WHERE user_id = "' . $user . '"', $mysql);
if ($result = mysql_fetch_array()) {
    die($result[0]);
}
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Post Count Page?

Post by Benjamin »

Ok. This will need to be cached for 5-15 minutes or so using APC or a file based cache so it doesn't nail the database. I will need to see if we can increase the memory allowance to APC, because it's full.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Post Count Page?

Post by Jonah Bron »

Hm, well I don't want to cause any inconvenience with this... if you have to apply any thing more than a few seconds of effort, well, you know, I'll live without it. :)

Edit: Perhaps I could just hack up something where it only allows certain people to access the post counter? Like this:

Code: Select all

<?php
if (!isset($_GET['u'])) {
    die('0');
}
$enabled_users = array(
    30233,
    12345
);
if (!in_array($_GET['u'], $enabled_users)) {
    die('0');
}
$user = mysql_real_escape_string($_GET['u']);
$mysql = mysql_connect('host', 'user', 'pass', 'db');
$query = mysql_query('SELECT user_posts FROM phpbb_users WHERE user_id = "' . $user . '"', $mysql);
if ($result = mysql_fetch_array()) {
    die($result[0]);
}
?>
And trusted users can ask to be manually put into the $enabled_users array, as long as they promise to cache it themselves :wink:
Post Reply