Sandi Budic Sandi Budic - 10 months ago 55
MySQL Question

Display button based on database role

I have a MySQL database with a PHP frontend. Is possible in PHP to create something like admin permission on

? Can i put on my "download"
permission to only admin can access it? (only admin can download
table with some information)

Sorry for my bad English.

enter image description here

Answer Source

STEP-1: When you validate user login successfully, assign some flag like $_SESSION['flag'] = "user";. And do the same for admin like: $_SESSION['flag'] = "admin";

   // login successful, then assign session 
   $_SESSION['flag'] = "admin";   
   // or for normal user
   $_SESSION['flag'] = "user";

STEP-2: Use this session variable to identify is user is admin or normal user and show or hide the download button like:


  if(isset($_SESSION['flag']) && !empty($_SESSION['flag']) && $_SESSION['flag']=="admin"){
       // code here for admin - show download button as you want!
       echo "<button id='btn_download'> Download </button>";
  } // else { // code here for normal user }