Free2Code
The majority of forums are now only available as archives, which means posting/editing is disabled.

The Anything and Everything forum is still open.
 
Time: 2013-05-24, 03:43am
Restricted access
Subject: Restricted access  ·  Posted: 2006-02-01, 01:56am
Rank: ? (5)
Member #: 26537
Hello,
first of all, want to let you know that this web site helped me a lot in learning PHP.
I am still learning, so sometimes I have questions that I can not not address without help from experts.
Here is one of them. I have a loging system which works fine. Users get registered, can login, change their account details, I can restrict access to some pages only to users that are logged in, but my problem now is that I really need to have certain group of users to have access to only certain pages.
Here how I restrict access with logged in session (works fine)
<?
include("../include/session.php";
?>
<html>
<?
/* User is not logged in */
if(!$session->logged_in){
?>

<body>
"You are not allowed to view this page"
</body>

<?
}
/* User is logged in */
else{
?>

<body>
bla-bla-bla (some html code)

Now I need to have a session that would check for user level and grant access to users with specific level.
I have tried this (but it does not work)
<?
include("include/session.php";
?>
<html>
<?

if(!$session->userlevel == 2){
?>

<body>
"You are not allowed to view this page"
</body>

<?
}

else{
?>

<body>
bla-bla-bla

The above code let's everyone lwho is logged in, view the page, no matter whal level they have.
Can somebody tell what I am doing wrong?
Any help or suggestions would be greatly appreciated.
Thank you in advance.
Regards,
Victoria

 
  Reply to this ·  Post link ·  Top
Subject: Re: Restricted access  ·  Posted: 2006-02-01, 03:29am
Rank: ? (4827)
Member #: 3416
your if statment if(!$session->userlevel == 2) looks like it's always false. if you're trying to deny access to everyone who is not userlevel 2, try this instead:

if($session->userlevel != 2)

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Re: Restricted access  ·  Posted: 2006-02-01, 03:56am
Rank: ? (5)
Member #: 26537
Dear misterhaan,
thank you sooooo much for your help!!! It worked right away!!
Wow, I have spent so much time trying to figure this out on my own
Thank you once again for your fast and helpful reply

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

Penguino AVR

Want to learn about robotics or microcontrollers?
Check out the Penguino AVR from our friends at
Icy Labs