Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); // STARTING THE SESSION!
- ?>
- <html>
- <head>
- <title>Index</title>
- </head>
- <body>
- <!--database connection-->
- <?php
- //error_reporting(0);
- $con = new mysqli('localhost', 'user', 'password', 'dbname');
- if($con->connect_errno > 0){
- die('Sorry, We\'re experiencing some connection problems.');
- }
- ?>
- <!--functions-->
- <?php
- function loggedin(){
- $_SESSION['user_id'] = 12; //EMULATING USER LOGGING TO SYSTEM!
- if(isset($_SESSION['user_id'])){
- return true;
- }else{
- return false;
- }
- }
- ?>
- <!--titlebar-->
- <div>
- <?php
- if(loggedin()){
- $my_id=$_SESSION['user_id'];
- if ($log = $con->prepare("SELECT username,user_level FROM users WHERE user_id=?")) {
- $log->bind_param("s", $my_id);
- $log->execute();
- $log->bind_result($username, $user_level);
- if($log->fetch()) //fetching the contents of the row
- {
- if($user_level=='a'){?>
- <a href = 'index.php'>Home</a>
- <a href = 'admin.php'>Admin</a>
- <a href = 'index.php'>Log Out</a>
- <?php } if($user_level=='m') { ?>
- <a href = 'index.php'>Home</a>
- <a href = 'profile.php'>Profile</a>
- <a href = 'index.php'>Log Out</a>
- <?php } else { ?>
- <a href = 'index.php'>Home</a>
- <a href = 'login.php'>Login</a>
- <a href = 'register.php'>Register</a>
- <?php
- }
- }
- } else {
- print 'Incorrect statement...';
- }
- }
- ?>
- </div>
- Index
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement