title: Displaying content based on user session PHP
body: <p><strong>* I've solved this. Thanks for the help /*</strong></p>
  
  <p>I am attempting to show some images to different users depending on their user_id / username. </p>
  
  <p>I am trying to do so by using userSession. </p>
  
  <p>I tried by using this code:</p>
  
  <pre><code> &lt;?php
  
  if ($_SESSION['user_id'] == 'Charlie') {
        // do admin
     &lt;li  class="span4 gallery-item" data-id="id-1"&gt;
        &lt;img class="fancybox" src="img/photoshop2_small.jpg" data-big="img/photoshop2.jpg" /&gt; &lt;/li&gt;
          }
  
     ?&gt;
  </code></pre>
  
  <p>I also tried "userSession" and "user_email". None worked.</p>
  
  <p>It cannot even load my website when I type in the code above. When I remove it, it loads perfectly.</p>
  
  <p>Here's my home.php class which is the one that loads when a user is logged in.  It's the same for everything atm but I am trying to display just certain images to the users depending on who they are. They have no special rank or anything.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  session_start();
  include_once 'dbconnect.php';
  
  if(!isset($_SESSION['userSession']))
  {
   header("Location: index2.php");
  }
  
  $query = $MySQLi_CON-&gt;query("SELECT * FROM users WHERE user_id=".$_SESSION['userSession']);
  $userRow=$query-&gt;fetch_array();
  $MySQLi_CON-&gt;close();
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  
      &lt;!-- CSS
      ================================================== --&gt;
      &lt;link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'&gt;
      &lt;link rel="stylesheet" href="css/bootstrap.css"&gt;
      &lt;link rel="stylesheet" href="css/bootstrap-responsive.css"&gt;
      &lt;!--&lt;link rel="stylesheet" href="css/prettyPhoto.css" /&gt;--&gt;
      &lt;!--&lt;link rel="stylesheet" href="css/flexslider.css" /&gt;--&gt;
      &lt;link rel="stylesheet" href="css/custom-styles.css"&gt;
  
      &lt;!--[if lt IE 9]&gt;
      &lt;script src="http://html5shim.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" href="css/style-ie.css"/&gt;
      &lt;![endif]--&gt;
  
      &lt;!-- Favicons
      ================================================== --&gt;
      &lt;link rel="shortcut icon" href="img/favicon.ico"&gt;
      &lt;link rel="apple-touch-icon" href="img/apple-touch-icon.png"&gt;
      &lt;link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72.png"&gt;
      &lt;link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114.png"&gt;
  
  
  
      &lt;!--Fancybox dwuser.com--&gt;
      &lt;link rel="stylesheet" type="text/css" media="screen" href="http://cdnjs.cloudflare.com/ajax/libs/fancybox/1.3.4/jquery.fancybox-1.3.4.css" /&gt;
      &lt;style type="text/css"&gt;
          a.fancybox img {
              border: none;
              -o-transform: scale(1,1); -ms-transform: scale(1,1); -moz-transform: scale(1,1); -webkit-transform: scale(1,1); transform: scale(1,1); -o-transition: all 0.2s ease-in-out; -ms-transition: all 0.2s ease-in-out; -moz-transition: all 0.2s ease-in-out; -webkit-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out;
          }
          a.fancybox:hover img {
              position: relative; z-index: 999; -o-transform: scale(1.03,1.03); -ms-transform: scale(1.03,1.03); -moz-transform: scale(1.03,1.03); -webkit-transform: scale(1.03,1.03); transform: scale(1.03,1.03);
          }
      &lt;/style&gt;
  
      &lt;!--Fancybox end--&gt;
  
  
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;title&gt;Test |  &lt;?php echo $userRow['user_email']; ?&gt;&lt;/title&gt;
  
      &lt;link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"&gt;
      &lt;link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen"&gt;
  
      &lt;link rel="stylesheet" href="css/style.css" type="text/css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  
  &lt;div class="color-bar-1"&gt;&lt;/div&gt;
  &lt;div class="color-bar-2 color-bg"&gt;&lt;/div&gt;
  
  &lt;div class="container main-container"&gt;
  
      &lt;div class="row header"&gt;&lt;!-- Begin Header --&gt;
  
          &lt;!-- Logo
          ================================================== --&gt;
          &lt;div class="span5 logo"&gt;
              &lt;a href="index.htm"&gt;&lt;img src="img/%20black.png" alt="" /&gt;&lt;/a&gt;
  
          &lt;/div&gt;
  
          &lt;!-- Main Navigation
          ================================================== --&gt;
          &lt;div class="span7 navigation"&gt;
              &lt;div class="navbar hidden-phone"&gt;
  
                  &lt;ul class="nav"&gt;
  
  
                      &lt;li&gt;&lt;a href="index.htm"&gt;Hjem&lt;/a&gt;&lt;/li&gt;
  
  
                      &lt;li class="dropdown"&gt;
                          &lt;a class="dropdown-toggle" data-toggle="dropdown" href="gallery.html"&gt;Galleri &lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt;
                          &lt;ul class="dropdown-menu"&gt;
                              &lt;li&gt;&lt;a href="gallery.html"&gt;Galleri&lt;/a&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;a href="wedding.html"&gt;Bryllup&lt;/a&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;a href="portrait.html"&gt;Portræt&lt;/a&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;a href="outside.html"&gt;Udendørs&lt;/a&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;a href="andet.html"&gt;Andet&lt;/a&gt;&lt;/li&gt;
                              &lt;!--&lt;li&gt;&lt;a href="gallery-single.htm"&gt;&lt;/a&gt;&lt;/li&gt;--&gt;
                          &lt;/ul&gt;
                      &lt;/li&gt;
  
  
  
                      &lt;li&gt;&lt;a href="page-contact.htm"&gt;Kontakt&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
  
  
                      &lt;!-- Username and logout button .... nav bar only --&gt;
                  &lt;ul class="nav navbar-nav navbar-right"&gt;
                      &lt;li&gt;&lt;a href="#"&gt;&lt;span class="glyphicon glyphicon-user"&gt;&lt;/span&gt;&amp;nbsp; &lt;?php echo $userRow['user_name']; ?&gt;&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="logout.php?logout"&gt;&lt;span class="glyphicon glyphicon-log-out"&gt;&lt;/span&gt;&amp;nbsp; Logout&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
  
              &lt;/div&gt;
  
  
          &lt;/div&gt;
  
      &lt;/div&gt;&lt;!-- End Header --&gt;
  
  
      &lt;div class="row headline"&gt;&lt;!-- Begin Headline --&gt;
  
          &lt;!-- Page Content
          ================================================== --&gt;
          &lt;div class="row"&gt;
  
              &lt;!-- Gallery Items
              ================================================== --&gt;
              &lt;div class="span12 gallery"&gt;
  
                  &lt;div class="row clearfix"&gt;
                      &lt;ul class="gallery-post-grid holder"&gt;
  
                          &lt;h6&gt;Tryk på billederne for at forstørre dem og for at opnå bedre kvalitet&lt;/h6&gt;
  
  
  
  
  
  
                             &lt;li  class="span4 gallery-item" data-id="id-1"&gt;
                              &lt;img class="fancybox" src="img/photoshop2_small.jpg" data-big="img/photoshop2.jpg" /&gt;
                              &lt;/li&gt;
  
  
  
  
                              &lt;li  class="span4 gallery-item" data-id="id-2"&gt;
                                  &lt;img class="fancybox" src="img/IMG_2205-Edit-1_small.jpg" data-big="img/IMG_2205-Edit-1.jpg" /&gt;
                              &lt;/li&gt;
  
  
                      &lt;/ul&gt;
                  &lt;/div&gt;
  
  
              &lt;/div&gt;&lt;!-- End gallery list--&gt;
  
          &lt;/div&gt;&lt;!-- End container row --&gt;
  
      &lt;/div&gt; &lt;!-- End Container --&gt;
  
      &lt;!-- Footer Area
          ================================================== --&gt;
      &lt;div class="row"&gt;&lt;!-- Begin Bottom Section --&gt;
  
  
  
      &lt;/div&gt;&lt;!-- End Bottom Section --&gt;
  
  &lt;/div&gt; &lt;!-- End Container --&gt;
  
  
  
  
  
  &lt;!-- Scroll to Top --&gt;
  &lt;div id="toTop" class="hidden-phone hidden-tablet"&gt;Back to Top&lt;/div&gt;
  
  &lt;!-- JS
     ================================================== --&gt;
  &lt;script src="http://code.jquery.com/jquery-1.8.3.min.js"&gt;&lt;/script&gt;
  &lt;!--&lt;script src="js/jquery.easing.1.3.js"&gt;&lt;/script&gt;--&gt;
  &lt;script src="js/bootstrap.js"&gt;&lt;/script&gt;
  &lt;!--&lt;script src="js/jquery.prettyPhoto.js"&gt;&lt;/script&gt;--&gt;
  &lt;!--&lt;script src="js/jquery.quicksand.js"&gt;&lt;/script&gt;--&gt;
  &lt;!--&lt;script src="js/jquery.custom.js"&gt;&lt;/script&gt;--&gt;
  
  
  &lt;!--Fancybox script--&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/fancybox/1.3.4/jquery.fancybox-1.3.4.pack.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(function($){
          var addToAll = false;
          var gallery = true;
          var titlePosition = 'inside';
          $(addToAll ? 'img' : 'img.fancybox').each(function(){
              var $this = $(this);
              var title = $this.attr('title');
              var src = $this.attr('data-big') || $this.attr('src');
              var a = $('&lt;a href="#" class="fancybox"&gt;&lt;/a&gt;').attr('href', src).attr('title', title);
              $this.wrap(a);
          });
          if (gallery)
              $('a.fancybox').attr('rel', 'fancyboxgallery');
          $('a.fancybox').fancybox({
              titlePosition: titlePosition
          });
      });
      $.noConflict();
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>