Jump to content

how to let selecter users view a page?


rallokkcaz

Recommended Posts

how to let selecter users view a page?
i don't know how to do the code

here the the code i wanna add the script too.
[code]<?PHP

include ("config.php");

//if the user is not logged in, then redirect to login page.
if (!is_logged_in($user)) {
    header("Location: users.php");  die();
}else{
      include ("header.php");
      //put your code here (protected page).
echo "";
include ("pic_upload.php");
}
?>[/code]
thanks in advanced
Link to comment
https://forums.phpfreaks.com/topic/18501-how-to-let-selecter-users-view-a-page/
Share on other sites

the code you have provided already is a rough sketch of showing a certain page based on whether a user is logged in or not.  the first part:

[code]
if(!is_logged_in($user)) {
  header("Location: users.php"); die();
}
[/code]
calls a function called is_logged_in, passing the variable $user to it. if it returns false, then it redirects you to users.php. if it returns true, it includes your header.php.  So what you need is the is_logged_in function that checks to see if someone is logged in, and oh yeah, the actual login script where someone can login. 
ok well.. the way the other person was going with the 0, 1, 2, 3 etc...  is global grouplevels.  if you just want lets say two people to view.. then just grab the row IDs of the users you want and put them in an IF statement.  for example..

BELOW WOULD BE PART OF THE MYSQL DATABASE
[table]
[tr][td]USERID[/td][td]USERNAME[/td][/tr]
[tr][td]1[/td][td]Bobby1041[/td][/tr]
[tr][td]2[/td][td]AnUnknownUser[/td][/tr]
[/table]

Then.. make an if statement that just allows the people with those two userids to view it.. and if the userid is different use HEADER to move them to a new page.. or display a message.
> If you need further help please reply or PM me.
okay, assuming that the rest of your code already works, in the code you originally provided, you have that variable $user, which i'm going to assume is the user's name.  so let's modify your code up there a bit:
[code]
<?PHP

include ("config.php");

//if the user is not logged in, then redirect to login page.
if (!is_logged_in($user)) {
    header("Location: users.php");  die();
}else{
  if ($user != "brad" || $user != "mike") {
      header("Location: users.php");  die(); // or relocate to some other access-denied page
  } else {
      include ("header.php");
      //put your code here (protected page).
    echo "";
    include ("pic_upload.php");
  }
}
?>
[/code]

Archived

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

×
×
  • 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.