Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2012
    Posts
    102
    Thanks
    5
    Thanked 3 Times in 3 Posts

    stuck with admin panel coding

    I am developing an admin panel for a website.

    So far I have the login form done and the accompanying form processing page which recognizes the user that logged in with a "welcome <user>!" message with a redirectiong message.

    Welcome, <user>!

    You are now logged into the backend. You will be redirected to the index portal momentarily.

    If you are not redirected automatically, please click here.
    The landing page is where I am having issues. The intention is to recognize the logged in user, and have different menu options based on userlevel..

    The welcome message has been migrated but returns:

    "Wlcome $f_name!"

    instead of "Welcome <user>!.. And with a known user being logged in, with the appropriate userlevel the menu options do not show.

    PHP Code:
    <?php
    //check for required authorization cookie
    if ($_COOKIE['auth'] != 1) {
        
    header("Location: /ctechinfo_new/login.php");
        
    end;
    }
    //connect to server and select database
    $mysqli mysqli_connect('localhost''root''''ctechinfo')
                or die(
    mysqli_error());
        
    //create and issue the query
    $sql "SELECT `f_name`, `userlevel` FROM `auth_users`";
    $result mysqli_query($mysqli$sql) or die (mysqli_error());

                    
    while (
    $info mysqli_fetch_array($result)) {
            
    $f_name stripslashes($info['f_name']);
            
    $userlevel stripslashes($info['userlevel']);
        }
        
    mysqli_close($mysqli);
    $meta_title "Ctechinfo.net :: Backend Index";
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/DTD/loose.dtd">
    <html>
      <head>
        <title><?php echo $meta_title?></title>
        <link rel="stylesheet" type="text/css" href="./css/layout.css" />
      </head>
    <body>

    <?php
        
    echo "<p>Welcome, ".'$f_name'."!</p>";
        if(
    $userlevel == 1) {
        echo 
    "<h1>Administrator Tools</h1>";
        echo 
    "<ul><li><a href=\"backend/add_user.php\">Add User</a></li>";
        echo 
    "<li><a href=\"backend/user_admin.php\">User Administration</a></li></ul>";
        echo 
    "<h1>Contributor Tools</h1>";
        echo 
    "<ul><li><a href=\"backend/add_board.php\">Add New Motherboard</a></li></ul>";
        }
    ?>

    </body>
    </html>

  2. #2
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,640
    Thanks
    11
    Thanked 165 Times in 160 Posts
    You are not specifying what user you are dealing with. You are selecting all users.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  3. #3
    Regular Coder
    Join Date
    Sep 2012
    Posts
    102
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by benanamen View Post
    You are not specifying what user you are dealing with. You are selecting all users.
    So essentially the only part of the code that is "good" is the cookie since if I try to view the page when not logged in I get redirected to the login page.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •