Jump to content

Archived

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

rallokkcaz

how to let selecter users view a page?

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

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites
ok ive got the whole thing
a login , register, and forgot password page.

but they are all within the page users.php

so it goes like

users.php?maa=register
ect.

thats the login page

Share this post


Link to post
Share on other sites
so then what's the problem? the code you have provided, assuming that your function works and your variables are being passed right, etc.. should work.

Share this post


Link to post
Share on other sites
i don't have a problem

i need a script that only allows certain user to view it

(example) say i only want user1 and user2 to view page.php
so user3 can't look at the page.

get my drift now? ???

Share this post


Link to post
Share on other sites
well, you could add a userlevel field for your users. a simple integer field that holds for instance  0,1,2, etc.. and check the user's level. if they aren't high enough, then they don't get to view the page.

Share this post


Link to post
Share on other sites
ok i don't want like 1 2 3
stuff i just want to allow 2 users to view this one page!

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
ok that doesn't work
no matter who im logged in as it automaticly
redirects me to users.php

help!!

Share this post


Link to post
Share on other sites
first off, did you change "mike" and "brad" to the correct user names? 2nd, try echoing $user to see what it is holding.

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.