Advertisement
Guest User

Untitled

a guest
Jul 5th, 2013
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2. session_start(); // STARTING THE SESSION!
  3. ?>
  4. <html>
  5. <head>
  6.     <title>Index</title>
  7. </head>
  8. <body>
  9.  
  10. <!--database connection-->
  11.  
  12. <?php
  13. //error_reporting(0);
  14. $con = new mysqli('localhost', 'user', 'password', 'dbname');
  15. if($con->connect_errno > 0){
  16.     die('Sorry, We\'re experiencing some connection problems.');
  17. }
  18. ?>
  19.  
  20. <!--functions-->
  21.  
  22. <?php
  23. function loggedin(){
  24.     $_SESSION['user_id'] = 12; //EMULATING USER LOGGING TO SYSTEM!
  25.     if(isset($_SESSION['user_id'])){
  26.         return true;
  27.     }else{
  28.         return false;
  29.     }
  30. }
  31. ?>
  32.  
  33.  
  34. <!--titlebar-->
  35.  
  36. <div>
  37.     <?php
  38.     if(loggedin()){
  39.         $my_id=$_SESSION['user_id'];
  40.         if ($log = $con->prepare("SELECT username,user_level FROM users WHERE user_id=?")) {
  41.             $log->bind_param("s", $my_id);
  42.             $log->execute();
  43.             $log->bind_result($username, $user_level);
  44.             if($log->fetch()) //fetching the contents of the row
  45.             {
  46.                 if($user_level=='a'){?>
  47.                     <a href = 'index.php'>Home</a>
  48.                     <a href = 'admin.php'>Admin</a>
  49.                     <a href = 'index.php'>Log Out</a>
  50.                 <?php } if($user_level=='m') { ?>
  51.                     <a href = 'index.php'>Home</a>
  52.                     <a href = 'profile.php'>Profile</a>
  53.                     <a href = 'index.php'>Log Out</a>
  54.                 <?php } else { ?>
  55.                     <a href = 'index.php'>Home</a>
  56.                     <a href = 'login.php'>Login</a>
  57.                     <a href = 'register.php'>Register</a>
  58.                 <?php
  59.                 }
  60.             }
  61.         } else {
  62.             print 'Incorrect statement...';
  63.         }
  64.     }
  65.     ?>
  66.  
  67. </div>
  68. Index
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement