Page that changes player's usergroup

Forum
Last Post
Threads / Messages

Derpstra

Seamstress!
Member
Joined
Aug 13, 2012
Messages
26
Points
0
Location
Seattle, WA/Charlotte, NC
Mysidian Dollar
3,434
Since I just made a script to change the user's money, I thought I would go ahead and make one to change their usergroup as well. This seems especially useful if you have a group for people who donate or contribute to the site and you want to automatically change their usergroup when they buy something or whatever.

first, add this function to the page functions/functions_users.php:

PHP:
function changeusergroup($newusergroup, $user) {
	$currentusergroup = $newusergroup;
	if ($currentusergroup >= 0) {
		$GLOBALS['adopts']->update("users", array("usergroup" => $currentusergroup), "username = '{$user}'");
		return true;
	}
	return false;
}
I placed mine under the function 'changecash' because they are so closely related.

then make a new page for the script. I called mine changeusergroup.php but you can call yours whatever you like!

PHP:
<?php

include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("functions/functions_friends.php");
include("functions/functions_items.php");
include("inc/lang.php");
include("inc/bbcode.php");

//***************//
//  START SCRIPT //
//***************//

$newgroup= 1;

if($isloggedin == "yes"){
changeusergroup($newgroup, $GLOBALS['username']);
$article_title = "Hello, {$username}!";
$article_content = "You are now in usergroup {$newgroup}.";
}
else{
$article_title = "You are not logged in!";
$article_content = "You must be logged in to view this page!";
}

//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title, $article_content, $date);
?>
When they get to this page, their usergroup will change to the variable $newgroup. For my example, i set it to 1, which would make them an administrator. You'll want to change the number to the group id for your premium member group or whatever you want to change them to!
 
How do I know which page this is located on? Sorry if I sound stupid, I'm very much a beginner when it comes to this sort of thing.

I've made it newgroup 7 for premium members, but where do I enter information to choose which page makes them change usergroup?
 
you need to go to function/functions_users.php which is located in your root of hosting files and add this code -
function changeusergroup($newusergroup, $user) {
$currentusergroup = $newusergroup;
if ($currentusergroup >= 0) {
$GLOBALS['adopts']->update("users", array("usergroup" => $currentusergroup), "username = '{$user}'");
return true;
}
return false;
}

then you need to create another page called changeusergroup.php and post this code -
<?php

include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("functions/functions_friends.php");
include("functions/functions_items.php");
include("inc/lang.php");
include("inc/bbcode.php");

//***************//
// START SCRIPT //
//***************//

$newgroup= 1;

if($isloggedin == "yes"){
changeusergroup($newgroup, $GLOBALS['username']);
$article_title = "Hello, {$username}!";
$article_content = "You are now in usergroup {$newgroup}.";
}
else{
$article_title = "You are not logged in!";
$article_content = "You must be logged in to view this page!";
}

//***************//
// OUTPUT PAGE //
//***************//

echo showpage($article_title, $article_content, $date);
?>

but remember function_user.php is in function folder and you need to create new file called changeusergroup.php in main directory
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,267
Messages
33,049
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top