PDA

View Full Version : Random User Selection Hack


ChrisBaktis
12-29-2004, 05:20 PM
I know i have seen a hack that allows the system to randomly pick a users name that appears in a forum. I am starting a Random Giveaway every month on my sports card trading site and would like a hack that will randomly select a user from the user database....can anyone point me in the right direction?

Chris

Jolten
12-31-2004, 12:42 AM
How exactly do you want this to work?

This will select a random username from all registered users with each and every page load.

in global.php

find (around line 548):

// parse headinclude, header & footer
eval('$headinclude = "' . fetch_template('headinclude') . '";');
eval('$header = "' . fetch_template('header') . '";');
eval('$footer = "' . fetch_template('footer') . '";');
if ($shownewpm)
{
if ($bbuserinfo['pmunread'] == 1)
{
$pmpopupurl = "private.php?$session[sessionurl_js]do=showpm&pmid=$newpm[pmid]";
}
else
{
$pmpopupurl = "private.php?$session[sessionurl_js]";
}
eval('$footer .= "' . fetch_template('pm_popup_script') . '";');
}


Insert AFTER that:

$who=$DB_site->query_first("SELECT username, usergroupid, userid FROM " . TABLE_PREFIX . "user WHERE usergroupid='2' ORDER BY rand() LIMIT 1");
$rUsr=$who['username'];


Note the usergroup='2' clause. This query is set to ONLY choose usernames from registered users, no other user group will show up. If you want to add more usergroups add more where clauses or delete "WHERE usergroupid='2'" if you want to pull from all usergroups (but that will include banned and waiting for confirmation as well.)

Then in any template add $rUsr where ever you want the username to appear.

ChrisBaktis
01-01-2005, 12:23 PM
Is there a way to use this code so I can do this via the admin area? What I would love to be able to do is have a 'Random User Selection' option in the admincp area...then when I click on that it will choose the random user and just print it in that area...so I would need help on adding the link in the admin cp area and then also where I add a template for the admin area.

If you can help with this that would be great!

Dean C
01-01-2005, 02:15 PM
Here you go:

https://vborg.vbsupport.ru/showthread.php?p=588552#post588552

ChrisBaktis
01-02-2005, 01:53 AM
Thank you - Thank you - Thank you!!!

I requested this hack because I run a sports card trading site. On this site we received product from sponsors that we give out to members. I was looking for something to pick a random user every month from the entire member base - not just a thread where a member posts.

Thank you again for the hack!