Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/20008-no-access/
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
}
Link to comment
https://forums.phpfreaks.com/topic/20008-no-access/#findComment-87738
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
Link to comment
https://forums.phpfreaks.com/topic/20008-no-access/#findComment-87744
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
Link to comment
https://forums.phpfreaks.com/topic/20008-no-access/#findComment-87747
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.