Blackicer Posted September 7, 2006 Share Posted September 7, 2006 ok, say you have a site and people want to gain access..now, in your mysql database you have a field called level, in that level only those >5 can view the page. how do you stop others from viewing it. i dunno if i made that clear enough... but what i wanna do is granted the page(s) do exist.. just make it look like it don't exist. Quote Link to comment https://forums.phpfreaks.com/topic/20008-no-access/ Share on other sites More sharing options...
AdRock Posted September 7, 2006 Share Posted September 7, 2006 you need to use sessionsIs the page only able to be viewed by people who have registered and have access level greater than 5?On the page where you want to only allow level 5 access you use something likesession_start();session_register("session");[code]if(!isset($session['userlevel'])=>5){echo "<center><font face='Verdana' size='2' color=red>Sorry, you don't have sufficent access rights to use this page </font></center>";exit;[/code]I'm not sure if i got the =>5 bit in the right place but it's along those lines } Quote Link to comment https://forums.phpfreaks.com/topic/20008-no-access/#findComment-87738 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 That code's not quite right...[code]if(!isset($session['userlevel'])=>5){echo "<center><font face='Verdana' size='2' color=red>Sorry, you don't have sufficent access rights to use this page </font></center>";exit;[/code]Notice the [b][color=red]![/color][/b] before the isset()... That means negative, so in essence you're saying "if the session isn't set, and is greater than 5"... That will always evaluate to false, as something that has no value can never be greater than 5.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20008-no-access/#findComment-87744 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 Try setting the session variable of 'userlevel' once a user's logged in and then use this...[code]<?phpif ((!isset($_SESSION['userlevel'])) || ($_SESSION['userlevel'] <= 5)){ // if the session's not set, or if it's less than or equal to 5 header("Location: index.php"); // forward them to our homepage}?>[/code]RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20008-no-access/#findComment-87747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.