Connecting Tech Pros Worldwide Help | Site Map

Using sessions in php

Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#1: Mar 26 '08
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's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: Mar 26 '08

re: Using sessions in php


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_menu.php");
}
[/php]

hope this helps!
Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#3: Mar 26 '08

re: Using sessions in php


Quote:

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_menu.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?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: Mar 26 '08

re: Using sessions in php


Quote:

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?
Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#5: Mar 26 '08

re: Using sessions in php


Quote:

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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#6: Mar 26 '08

re: Using sessions in php


Quote:

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
Reply