Board index   FAQ   Search  
Register  Login
Board index php forum :: PHP and MySQL Security PHP & MySQL Security

Creating an admin

Security issues related to php and mysql usage. How to make your code secure? Security measures and configurations? It's all in here!

Moderators: macek, egami, gesf

Creating an admin

Postby vineeth1988 » Fri Mar 16, 2012 8:15 pm

:help: I am yet to do a stunning code with php. Can anyone help me to make an administrator account using php havin rights to create as many users and also have the right to edit te pages....
vineeth1988
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Feb 28, 2012 8:39 pm

Re: Creating an admin

Postby vineeth1988 » Sun Mar 18, 2012 9:52 pm

please somebody can help me from this juncture................................
vineeth1988
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Feb 28, 2012 8:39 pm

Re: Creating an admin

Postby JordanMRichards » Wed Apr 25, 2012 7:47 am

Hello vineeth,

I recommend you have a column in your table of users that says "Admin" make it an INT and make it DEFAULT of 0.

Then make a function with a query inside of it that checks to see if the column of Admin is 1 or not, if it is, then return true...

Something like this.

Code: Select all
function userisadmin() {
      $idname = $_SESSION['user_id'];  // your session name to determain the id of the user that is logged in
      $query = "SELECT Admin FROM users WHERE id ='$idname'";
      if ($query_run = mysql_query($query)) {
         if($query_result = mysql_result($query_run, 0, $field)) {
            if ($query_result == '1') {
               return true;
               }else{
               return false;
            }
      }
   }
}

// then on any page you could put
if (userisadmin()) {
//if they're an admin...
}else{
if they are not.
}


Hope this helped ;)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 Year Old Programmer & Graphic Artist, Confident and Courageous
Image
User avatar
JordanMRichards
New php-forum User
New php-forum User
 
Posts: 84
Joined: Mon Apr 23, 2012 7:43 am


Return to PHP & MySQL Security

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron