MyBB Community Forums

Full Version: PHP script to change user group?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to make a php script that when accessed automatically changes the user group. For example if the user goes to http://site.com/upgrade.php
If they are logged in then the script accesses the database and changes their group id#, is there any way of doing this?
Yes there is, it would require a few little things, I will get you a script made and added to a post a bit later tonight. Are you just wanting members to access it for upgrade only or what?
I'm looking to simply change their user group, the main idea is outlined below:

User clicks paypal button -> Purchases item -> IPN php script is called from http://site.com/1.php
This file stores their payment in a separate database, sends them an email, and should change their user group to a specified group id #.
I have a partial script written out:

<?php

define("IN_MYBB", 1);
require_once "./global.php";
$userN = $mybb->user['uid'];
$userG = $mybb->user['usergroup'];

if($userN > 0)
{

$query = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup='8' WHERE uid='".$userN."'");

echo 'Username: '.$mybb->user['username'];
echo '<br>';
echo 'User ID#: '.$mybb->user['uid'];
echo '<br>';
echo 'Previous User Group ID: '.$userG.' & New Group ID: 8';

}
else
{
echo "User is not registered or signed in!";
}

//var_dump($mybb);

?>
Ah, gotcha. Do you have it set so the IPN reports back to that script before proceeding with the usergroup move?
I have it set up right now so that this script is a part of the IPN php script, you can also have it set up so that the IPN script calls a separate php script to change the user group after the payment has processed.

The idea is once the payment has completed, the IPN script is notified by Paypal with the "VERIFIED" keyword, the payment status should be checked to be completed, then the change user group script should be called to change the user's primary group to group id #8.

If you would like the full php script I can post it.