PDA

View Full Version : Plugin Vbulletin Variable for Usergroup ID


m002.p
01-13-2009, 07:40 PM
Hello everyone,

I have wrote a simple plugin script which runs under hook location login_verify_success which is intended to write the current users IP & Host to another MYSQL database on the same server as vbulletin.

The code ive formulated is pretty simple to me and working in principle, but when I wanted to add a check for vbulletin usergroups, it all went weird.

Basically as you will see in my plugin script, I want to check the usergroup of the member who has logged in successfully, and if they match one defined in the array, then run the MYSQL queries dependant on the output.

However to the point, the original variable I tried was the following:

if ($vbulletin->userinfo['usergroupid'] == 'x' || 'y' || 'z')
{
//Some Code
}

This worked and didnt. The code within the tags was executed so the conditional worked, however it worked for just about every usergroup and not only the ones defined which puzzled me.

So I tried another way I knew of:

if ( is_member_of($vbulletin->userinfo, explode(',', X,Y,Z))
{
//Some Code
}

Now the code within the tags just doesnt execute full stop, regardless of the usergroup the member belongs to.

Heres the full script:

// MYSQL Server Domain
$mysqldomain = "DOMAIN";

// MYSQL Server Username
$mysqluser = "USER";

// MYSQL Server Password
$mysqlpass = "PASS";

// MYSQL Database Name
$mysqldb = "TABLE";

mysql_connect($mysqldomain, $mysqluser, $mysqlpass) or die(mysql_error());
mysql_select_db($mysqldb) or die(mysql_error());

// Define Key Variables
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($ip);

if ( is_member_of($vbulletin->userinfo, explode(',', 9,10,11,19,12,24,20,13))
{

// MYSQL QUERIES

}else{

// DIFFERENT MYSQL QUERIES

}

Any ideas how I can get this working?
On a side note, I have used the $vbulletin->userinfo['userid'] variable in the MYSQL queries and there are no problems.

Thanks for any help in advance.

Matt

Lynne
01-13-2009, 08:10 PM
No need to do the explode:
if (is_member_of($vbulletin->userinfo,X,Y,Z))

Bellardia
01-13-2009, 08:15 PM
Your explode syntax won't work because you don't even have a string as a parameter.
Is there a reason you're using define database connections when the database is defined inside the $vbulletin class?
Your use of the OR operator is also incorrect.

Try checking their use at php.net

m002.p
01-13-2009, 08:23 PM
Your explode syntax won't work because you don't even have a string as a parameter.
Is there a reason you're using define database connections when the database is defined inside the $vbulletin class?
Your use of the OR operator is also incorrect.

Try checking their use at php.net

Thanks for replying.

The reason why I am defining the database connection info again is due to the fact the database is different to the one I use for vbulletin and which is obviously called from config.php. The server is the same (domain) but the connection info is different due to that factor.

Could you also define what you mean by the OR operator being incorrect? I assume you are referring to the "or die mysql_error()". It has always worked for me :s

Could anyone offer an explanation as to why the first conditional I tried didnt work fully?

Thanks to Lynne and Bellardia

EDIT: This still didnt fix my issue after using Lynne's code, but then I noticed there was a missing closing bracket. All is working as expected, thank you!

Matt

Bellardia
01-13-2009, 11:21 PM
Although not in your main code, you posted this

if ($vbulletin->userinfo['usergroupid'] == 'x' || 'y' || 'z')

A more correct use is

if ($vbulletin->userinfo['usergroupid'] == 'x' || $vbulletin->userinfo['usergroupid'] == 'y' || $vbulletin->userinfo['usergroupid'] == 'z')

Lynne
01-14-2009, 02:35 AM
EDIT: This still didnt fix my issue after using Lynne's code, but then I noticed there was a missing closing bracket. All is working as expected, thank you!

Matt
Argh! I need to double-check my parenthesis before posting! Sorry about that.

Dismounted
01-14-2009, 03:30 AM
The reason why I am defining the database connection info again is due to the fact the database is different to the one I use for vbulletin and which is obviously called from config.php. The server is the same (domain) but the connection info is different due to that factor.
As long as the MySQL user set in config.php has permissions to read your other database, you can do this inside your query (and save yourself starting another connection):
$vbulletin->db->query_read("
SELECT *
FROM database2.table3.field4
");