-2

Just seeing if this is possible and if so hoping for some direction, I'm still very new to php.
I'd like to use the user's session data turn on or off elements in a page. I think I need to create a php file that is storing this info, that way I can modify the website page elements user permissions but just adding or subtracting.
Something like:

user1 is equal access to: section 1,2,4,5

user2 is equal access to: section 3,5

user3 is equal access to: section 1,2,3,4,5,6

The section access (or how ever i would call this element) would be displaying only parts with those numbers assigned to the divs in the html layout of the page defined by user1, user2, or user3. Essentially granting access to portions of a page depending on the user's id permissions.

.deptTile {
  height: 100px;
  background-color: gainsboro;
  padding: 12px;
  border-radius: 2px;
  position: relitive;
  width: 420px;
  margin: 15px;
  
}
.deptTile:hover {
  background-color: #99E299;
  cursor: pointer !important;
}
@media (min-width: 1200px) .container {
  width:1170px;
}
@media (min-width: 1200px) .col-lg-4 {
  width:33.33333333%;
}
.row {
  margin-right: -15px;
  margin-left: -15px;
}
body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.42857143;
  color: #333;
  background-color: #fff;
}
@media (min-width: 1200px) .col-lg-4 {
  width:33.33333333%;
}
.media,
.media-body {
  overflow: hidden;
  zoom: 1;
}
@media (min-width: 1200px) .container {
  width:1170px;
}
body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.42857143;
  color: #333;
  background-color: #fff;
}
<div class="container" style="top: 150px; position: relative;">
  <div class="row" style="padding-bottom: 100px;">
    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-6" onMouseOver="">
      <div class="media-object-default">
        <div class="media deptTile" style="" onClick="">
          <div class="media-left" style="padding: 5px; margin: 5px; float: left;">
            <a href="">
              <img src="" alt="placeholder image" class="media-object img-responsive">
            </a>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Sales Dept.</h4>
            Click to see all the marketing materials. Product Image Database soon to come.</div>
        </div>
      </div>
    </div>
    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-6">
      <div class="media deptTile" style="" onClick="">
        <div class="media-left" style="padding: 5px; margin: 5px; float: left;">
          <a href="">
            <img src="" alt="placeholder image" class="media-object img-responsive">
          </a>
        </div>
        <div class="media-body">
          <h4 class="media-heading">Marketing Dept.</h4>
          Click to see all the marketing materials &amp; marketing reports.</div>
      </div>
    </div>
    <div class="col-lg-4 col-md-4 col-sm-6 hidden-sm hidden-xs">
      <div class="media deptTile" style="" onClick="">
        <div class="media-left" style="padding: 5px; margin: 5px; float: left;">
          <a href="">
            <img src="" alt="placeholder image" class="media-object img-responsive">
          </a>
        </div>
        <div class="media-body">
          <h4 class="media-heading">Admin</h4>
        </div>
      </div>
    </div>
    <div class="col-md-4 col-sm-6 col-lg-12"></div>

  </div>
</div>

once the user has logged in the session is created and i would like to use the session id to allow or disallow access to only one of the buttons, 2 or all three depending on the user's id associated with the logged in profile user id.

I'm so new to this I just saw that I can just type in html natively


ok, so I'm very new to php, just started a couple days ago memorizing the language for personal application, and now trying for my office.

I'm an art director not a backend designer, but I'm giving it all can

Really any direction at all would be helpful

2 Answers2

0

I have this placed at the top of my home.php in hopes find the user id's name from the session start.
Although, as you see this isn't going to work, or hadn't worked for me

<?php
   $msg1 = "Hello"

   if($_SESSION['userlogin'] == 'msg1'){
   echo $msg1;
   } else {
   header("Location: logout.php");
?>

I do have a start session function in my index.php

   private function doStartSession()
{
    session_start();
    $_SESSION['userlogin'] = $login; // TESTING TO SEE IF I CAN GRAB USER NAME AND USE IT ELSE WHERE TO DEFINE WHAT USER SEES ON THE SITE


}

So I'm sorta lost, is userlogin not what I want to grab?
This was just a test to see if I can get the username's id. I'm hoping to do something like you had before mentioned Tyler.

<?php
  session_start();
  if ($_SESSION['id'] == "userone") {
?>
 //html code if userone
  <h2>Hi userone</h2>
<?php
  } elseif ($_SESSION['id'] == "usertwo") {
?>
-1

You can definitely do things like that with session variables. Let's say you have this as a php file:

<?php
  session_start();
  if ($_SESSION['id'] == "userone") {
?>
  //html code if userone
  <h2>Hi userone</h2>
<?php
  } elseif ($_SESSION['id'] == "usertwo") {
?>
  //html code if user two
  <h2>hi usertwo</h2>
<?php
  } else {
?>
  //html code if neither of those
  <p>It appears that you are not logged in, so no welcome message</p>
<?php
  }
?>

Of course, you would have to have set the session variable "id" first somewhere else, on another page.

Tyler Collins
  • 127
  • 10
  • This is something along the line I had been hoping someone to show me. I didn't know this was possible. I'll need to do more studying to see just how to implement this. – handpaintedstudio Aug 05 '15 at 22:28
  • This is especially useful in navigation menus, such as hiding a group of links or items from a drop down. – Tyler Collins Aug 05 '15 at 22:44
  • It is a very primitive way, and would be very tedious, as you would basically have to have 3 whole page designs for just 2 users and a fallback. Once you play with this for a while, you'll probably come up with a little more specific of a question next round :) – Tyler Collins Aug 05 '15 at 22:45
  • Tyler, do you see any security problems with the above, especially considering Fred's [link](http://stackoverflow.com/q/31814668/) in comments under Question? In particular, what should be at the top of the script? – Drew Aug 05 '15 at 22:51
  • I am uncertain, teach us both and I will make the change in my answer. I don't see what you're referring to. Should we be checking to see that the variable is set first? – Tyler Collins Aug 06 '15 at 06:45