Jump to content

Archived

This topic is now archived and is closed to further replies.

Blackicer

no access

Recommended Posts

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.

Share this post


Link to post
Share on other sites
you need to use sessions

Is 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 like

session_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
}

Share this post


Link to post
Share on other sites
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.

Regards
Rich

Share this post


Link to post
Share on other sites
Try setting the session variable of 'userlevel' once a user's logged in and then use this...

[code]
<?php
if ((!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]

Regards
Rich

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.