Skip to content
Advertisement

PHP I want to restrict a button in the navbar to Admin users only

Currently making a blog websit and wanted to add an administrator locked button in the navbar that allows them to delete users there is onlly 1 Admin whos username will be “Admin”.

Right now I have something like this:

JavaScript

I keep getting this error Fatal error: Cannot use isset() on the result of an expression (you can use “null !== expression” instead) in C:xampphtdocspdo-blog-masterincludesnavbar.php on line 12

Any help will be appreciated.

Advertisement

Answer

You have an Error here:

if (isset($_SESSION['username'] == "Admin"))

You are trying to check if the result of the expression is set (true or false) which doesn’t work because isset() can’t used that way.

https://www.php.net/manual/en/function.isset.php

Change this to:

if (isset($_SESSION['username']) && $_SESSION['username'] === "Admin")

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement