Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to protect "display" page?
    text
    copied!<p>I want to protect "display" page based on AccessLevel of user who logged in </p> <p>function protect_page() doesn't work right it access any user with any accesslevel</p> <p>I use relation between two tables they are: privilege table </p> <pre><code> +----------------------------------+ | AccessLevel | login_id | pre_id| |----------------------------------| | 1 | 1 | 1 | | 2 | 1 | 2 | | 4 | 2 | 4 | +----------------------------------+ </code></pre> <p>and this is login_pre table:</p> <pre><code> +----------------------------------+ | username| userpass | login_id | |----------------------------------| | a | 123 | 1 | | a | 123 | 1 | | b | 1234 | 2 | +----------------------------------+ </code></pre> <p>and the code of privilege page </p> <pre><code>ob_start(); session_start(); include 'C:\xampp\htdocs\database\agtdatabase\agt_site\connection\connect.php'; $query ="SELECT * FROM privilege " ; $result = mysqli_query($link,$query) or die(''); if(isset($_SESSION['sessionloginid']))// point to id of user logged in { $query ="SELECT * FROM privilege where login_id='".$_SESSION['sessionloginid']."'" ; $result = mysqli_query($link,$query) or die(''); while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $access = $row['AccessLevel']; $_SESSION['sessionloginid']; echo $_SESSION['sessionaccess'];// output: 1 } } ob_end_flush(); </code></pre> <p>and code of protect page :</p> <pre><code>include_once('C:\xampp\htdocs\database\agtdatabase\agt_site\login2\privilege.php'); function login() { return (isset($_SESSION['sessionloginid'])) ? true:false ; echo $_SESSION['sessionloginid']; }login(); function privilege() { return $_SESSION['sessionaccess']; } function protect_page(){ if($_SESSION['sessionloginid']== true &amp;&amp; $_SESSION['sessionaccess'] !=1 ){ header ('location:http://localhost/database/agtdatabase/agt_site/agtSite/agt2.php'); //echo $_SESSION['sessionaccess']; output nothing when user a logged in exit(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload