lowheartrate

checkLogin() function

Nov 24th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. function checkLogin() {
  2.     // echo avatar, certain nav elements!!
  3.     echo '
  4.    <div class="navbar-right">
  5.       <!-- icons -->
  6.       <img src="http://i.imgur.com/HD6W7XJ.png" class="icon-search" alt="search-icon" />
  7.  
  8.       <a href="#p1">
  9.         <span class="icon-bars-button">
  10.            <span class="icon-bar"></span>
  11.            <span class="icon-bar"></span>
  12.            <span class="icon-bar"></span>
  13.         </span>
  14.       </a>
  15.  
  16.       <div class="page" id="p1-page">
  17.        <div id="shell">
  18.          <strong>ONE</strong>
  19.          <p>Know when you go to link two I will be covered behind panel 2.</p>
  20.  
  21.          <button>close</button>
  22.        </div>
  23.       </div>
  24.  
  25.    ';
  26.  
  27.     $username = $_SESSION['username'];
  28.  
  29.     // run query to get users avatar - Only select the columns you need.
  30.     $sql = "SELECT avatar FROM users WHERE username = :username";
  31.     $getAvatar = dbConnect()->prepare($sql);
  32.     $parameters = array(':username' => $username);
  33.     // execute query
  34.     $getAvatar->execute($parameters);
  35.  
  36.     // Check to see if rowCount returned any data
  37.     if($getAvatar->rowCount()) {
  38.  
  39.         // Loop the data in a while loop and create/ append the variable $row to the while loop.
  40.         while($row = $getAvatar->fetch(PDO::FETCH_ASSOC)) {
  41.  
  42.           // set $avatar as users set avatar
  43.           $avatar = $row['avatar']; // This data should be escaped.
  44.  
  45.           if(empty($avatar)) {
  46.  
  47.               // echo default avatar...
  48.               echo '<img src="http://i.imgur.com/QFxs0nX.png" class="user_avatar" alt="default avatar" />';
  49.  
  50.           // if user has set an avatar:
  51.           } else {
  52.  
  53.               // echo set avatar...
  54.               echo '<img src="includes/uploads/avatar/' .$avatar. '" class="user_avatar" alt="' .$username. ' avatar" />';
  55.  
  56.           }
  57.  
  58.         }
  59.   }
  60.   // check for errors logging in...
  61.   //checkLoginErrors();
  62. }
Add Comment
Please, Sign In to add comment