Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 365
1 Users 16 Guests Online

Making a user admin

I made this because InSaNe seems to be having some trouble adding himself admin:

addadmin.php:

(NOTE BECAUSE INSANE ISN'T ADMIN ON HIS SITE USE THIS CODE IF YOU ARE NOT AN ADMIN):

Code
<?php
include("config.php");
switch ($page) {

default:
echo "<form action='?page=admin' method='post'>
Username: <input type='text' name='user'><BR>
<input type='submit' value='Submit'></form>";
break;

case 'admin':
$admin = $_POST['user'];

$update = mysql_query("ALTER `members` SET `userlevel` = '6' WHERE `username` = '$admin'");
echo "$admin is now a admin.";
break;
}
?>


(IF YOU WANT TO MAKE THAT PASSWORD PROTECTED):

Code
<?php
include("config.php");
if($logged[username]) {
switch ($page) {

default:
echo "<form action='?page=admin' method='post'>
Username: <input type='text' name='user'><BR>
<input type='submit' value='Submit'></form>";
break;

case 'admin':
$admin = $_POST['user'];

$update = mysql_query("ALTER `members` SET `userlevel` = '6' WHERE `username` = '$admin'");
echo "$admin is now a admin.";
break;
}
}
?>


Easy, and simple. So there you go InSaNe, unless you figured out how to do it. Enjoy.
Diablosblizz
Views:
2694
Rating:
Posted on Wednesday 23rd July 2008 at 03:31 AM
UrbanTwitch
UrbanTwitch
Here is an add-on I made.

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
include("config.php");
if(
$logged[username] && $logged[userlevel] == 6) {
switch(
$_GET['promote']) {

default:
echo 
"<form action='?promote=user' method='post'>
Username: <input type='text' name='user'>
Level: <select name='level'>
<option value='0'>Banned</option>
<option value='1'>Unvalidated user</option>
<option value='2'>Validated User</option>
<option value='4'>Moderator</option>
<option value='6'>Administrator</option>
</select>
<input type='submit' value='Submit'></form>"
;
break;

case 
'user':
$admin $_POST['user'];
$level $_POST['level'];

$update mysql_query("UPDATE `members` SET `userlevel` = '$level' WHERE `username` = '$admin'");
if (
$_POST['level'] == 6)
{
//start private message
$to $admin//get who it is to
$from 'Bot'//who its from
$subject "Promotion!"//new subject
$msg "Hello, $admin$logged[username] promoted you to an Administrator!"//the content
$date date("F j, Y, g:i a"); //the date sent
$do mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" $to "','" $from "','" $date "','" $subject "','" $msg "')") or die(mysql_error()); //insert into the table!
//end private message
}
if (
$_POST['level'] == 4)
{
//start private message
$to $admin//get who it is to
$from 'Bot'//who its from
$subject "Promotion!"//new subject
$msg "Hello, $admin$logged[username] promoted you to a Moderator!"//the content
$date date("F j, Y, g:i a"); //the date sent
$do mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" $to "','" $from "','" $date "','" $subject "','" $msg "')") or die(mysql_error()); //insert into the table!
//end private message
}
echo 
"$admin is now a $level.";
break;
}
}
?>


You must have the Private Message system installed. What it does is that it notifies the user its been promoted by a private message.
Posted on Saturday 7th June 2008 at 10:11 PM
Diablosblizz
Diablosblizz
I am confused, could you elaborate more?
Posted on Saturday 7th June 2008 at 08:20 PM
eliel
eliel
For some reason this isn't working for me? I changed it and stuff kept the level to add my self an admin 0 then when it said i was an admin i changed back to 6 then i tried to acess the page again and it wouldn't let me enter it?
Posted on Sunday 4th May 2008 at 09:06 AM
JakkyD
JakkyD
Does unvalidated user count as a guest aswell?
Posted on Friday 26th October 2007 at 04:15 PM
Enros
Enros
Mate do you see the script $_session ??

If not then no you dont need the session start.
Posted on Thursday 25th October 2007 at 10:33 AM
Belloc
Belloc
Shouldn't thise have session_start(); in top ?
Posted on Tuesday 21st August 2007 at 04:47 PM
Diablosblizz
Diablosblizz
Edit, nevermind, I screwed up...

Nice eye New2Old.
Posted on Tuesday 21st August 2007 at 04:46 PM
Diablosblizz
Diablosblizz
New, the first code that I posted was for if you're an admin, but don't know how to use Phpmyadmin.

The second code was the protected one.

And good job on the Add on. ;)
Posted on Tuesday 21st August 2007 at 04:06 PM
new2old
new2old
ADD ON

make users diffrent levels other than just admin

Code

<?php
include("config.php");
if($logged[username] && $logged[userlevel] == 6) {
switch($_GET['page']) {

default:
echo "<form action='?page=admin' method='post'>
Username: <input type='text' name='user'><br />
Level: <select name='level'>
<option value='0'>Banned</option>
<option value='1'>Unvalidated user</option>
<option value='2'>Validated User</option>
<option value='4'>Moderator</option>
<option value='6'>Administrator</option>
</select>
<input type='submit' value='Submit'></form>";
break;

case 'admin':
$admin = $_POST['user'];
$level = $_POST['level'];

$update = mysql_query("UPDATE `members` SET `userlevel` = '$level' WHERE `username` = '$admin'");
echo "$admin is now a $level.";
break;
}
}
?>
Posted on Tuesday 21st August 2007 at 03:57 PM
new2old
new2old
change

if($logged[username]) {

to

if($logged[username] && $logged[userlevel] == 6) {

atm anyone can change a level to admin