Page 1 of 1

Post Count Page?

Posted: Mon Jun 14, 2010 6:01 pm
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!

Re: Post Count Page?

Posted: Fri Aug 27, 2010 3:23 pm
by Jonah Bron
Would it help if I threatened to scrape the site?

( :) not)

Re: Post Count Page?

Posted: Fri Aug 27, 2010 5:12 pm
by Benjamin
If you write it, I can tweak it for performance, then show it to the other mods for review.

Re: Post Count Page?

Posted: Fri Aug 27, 2010 7:12 pm
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]);
}
?>

Re: Post Count Page?

Posted: Sat Aug 28, 2010 2:32 pm
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.

Re: Post Count Page?

Posted: Sat Aug 28, 2010 8:06 pm
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: