Using sessions in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    #1

    Using sessions in php

    In my php application there are two users named as Admin and User. My login page has left side menues and i want to hide some menues to User.I want to use session and how can i do that? Could you please help me?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Well, assuming you know how to use sessions:
    [php]
    # after a log in
    # set a session for Admin or User
    $_SESSION['Access'] = "Admin";
    # this case is Admin
    [/php]

    [php]
    # show menus?
    if($_SESSION['Access'] == "Admin")
    {
    # include menus
    include("admin_ menu.php");
    }
    else
    {
    include("user_m enu.php");
    }
    [/php]

    hope this helps!

    Comment

    • ghjk
      Contributor
      • Jan 2008
      • 250

      #3
      Originally posted by markusn00b
      Well, assuming you know how to use sessions:
      [php]
      # after a log in
      # set a session for Admin or User
      $_SESSION['Access'] = "Admin";
      # this case is Admin
      [/php]

      [php]
      # show menus?
      if($_SESSION['Access'] == "Admin")
      {
      # include menus
      include("admin_ menu.php");
      }
      else
      {
      include("user_m enu.php");
      }
      [/php]

      hope this helps!


      Thanks for your reply. But how can i check whether Admin or User. Database has User type field and by using username and password can i do that?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by ghjk
        Thanks for your reply. But how can i check whether Admin or User. Database has User type field and by using username and password can i do that?
        Well, you'll need a login script for that.
        (When the user logs in, you find what access level they have, then assign that to a session)
        Do you have one?

        Comment

        • ghjk
          Contributor
          • Jan 2008
          • 250

          #5
          Originally posted by markusn00b
          Well, you'll need a login script for that.
          (When the user logs in, you find what access level they have, then assign that to a session)
          Do you have one?

          Could you give me some turorial or link ? Because i'm new to php and still confusing in using sessions.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by ghjk
            Could you give me some turorial or link ? Because i'm new to php and still confusing in using sessions.
            Sure thing, tizag have a good tutorial on sessions

            Comment

            Working...