lowheartrate

function checkLogin()

Nov 22nd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. function checkLogin() {
  2.   // originally header.php
  3.  
  4.   // if user is logged in
  5.   if(isset($_SESSION['username'])) {
  6.     $username = $_SESSION['username'];
  7.  
  8.     // run query to get users avatar
  9.     $getAvatar = dbConnect()->prepare("SELECT * FROM users WHERE username = :username");
  10.     $getAvatar->bindParam(':username', $username);
  11.     // execute query
  12.     $getAvatar->execute();
  13.     // set each column as row
  14.     $row = $getAvatar->fetch(PDO::FETCH_ASSOC);
  15.     // set $avatar as users set avatar
  16.     $avatar = $row['avatar'];
  17.  
  18.     // echo avatar, certain nav elements!!
  19.     echo '
  20.    <div class="navbar-right">
  21.       <!-- icons -->
  22.       <img src="http://i.imgur.com/HD6W7XJ.png" class="icon-search" alt="search-icon" />
  23.  
  24.       <span class="icon-bars-button">
  25.          <span class="icon-bar"></span>
  26.          <span class="icon-bar"></span>
  27.          <span class="icon-bar"></span>
  28.       </span>
  29.  
  30.    ';
  31.  
  32.     // if user doesn't have avatar set:
  33.     if (empty($avatar)) {
  34.  
  35.       // echo default avatar...
  36.       echo '<img src="http://i.imgur.com/QFxs0nX.png" class="user_avatar" alt="default avatar" />';
  37.  
  38.     // if user has set an avatar:
  39.     } else {
  40.  
  41.       // echo set avatar...
  42.       echo '
  43.      <!-- user avatar -->
  44.      <img src="data:image/jpeg;base64,' . base64_encode($avatar) . '" class="user_avatar" alt="' .$username. ' avatar" />
  45.      ';
  46.  
  47.     }
  48.  
  49.     echo '
  50.    </div>';
  51.  
  52.   // if user is not logged in ..
  53.     } else {
  54.  
  55.   // echo sign-up and log-in btns
  56.     echo '
  57.    <div class="navbar-right">
  58.       <!-- sign up / log in buttons -->
  59.       <a href="register.php"><button type="button" class="sign-up">Sign Up</button></a>
  60.       <a href="login.php"><button type="button" class="log-in">Log In</button></a>
  61.  
  62.       <!-- icons -->
  63.       <img src="http://i.imgur.com/HD6W7XJ.png" class="icon-search" alt="search-icon" />
  64.  
  65.       <span class="icon-bars-button">
  66.          <span class="icon-bar"></span>
  67.          <span class="icon-bar"></span>
  68.          <span class="icon-bar"></span>
  69.       </span>
  70.    </div>
  71.    ';
  72.   }
  73.   // check for errors logging in...
  74.   //checkLoginErrors();
  75. }
Add Comment
Please, Sign In to add comment