rallokkcaz Posted August 24, 2006 Share Posted August 24, 2006 how to let selecter users view a page?i don't know how to do the codehere the the code i wanna add the script too.[code]<?PHPinclude ("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 Quote Link to comment Share on other sites More sharing options...
.josh Posted August 24, 2006 Share Posted August 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted August 24, 2006 Author Share Posted August 24, 2006 ok ive got the whole thing a login , register, and forgot password page.but they are all within the page users.phpso it goes likeusers.php?maa=registerect.thats the login page Quote Link to comment Share on other sites More sharing options...
.josh Posted August 24, 2006 Share Posted August 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted August 24, 2006 Author Share Posted August 24, 2006 i don't have a problemi need a script that only allows certain user to view it(example) say i only want user1 and user2 to view page.phpso user3 can't look at the page.get my drift now? ??? Quote Link to comment Share on other sites More sharing options...
.josh Posted August 24, 2006 Share Posted August 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted August 24, 2006 Author Share Posted August 24, 2006 how do i do that? Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted August 24, 2006 Author Share Posted August 24, 2006 ok i don't want like 1 2 3 stuff i just want to allow 2 users to view this one page! Quote Link to comment Share on other sites More sharing options...
.josh Posted August 24, 2006 Share Posted August 24, 2006 two specific users and nobody else? just check for their username. Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted August 24, 2006 Author Share Posted August 24, 2006 how do i do that! ???and thanks for all the help! ;) Quote Link to comment Share on other sites More sharing options...
kickindrummerkid Posted August 24, 2006 Share Posted August 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
.josh Posted August 24, 2006 Share Posted August 24, 2006 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]<?PHPinclude ("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] Quote Link to comment Share on other sites More sharing options...
rallokkcaz Posted August 24, 2006 Author Share Posted August 24, 2006 ok that doesn't workno matter who im logged in as it automaticly redirects me to users.phphelp!! Quote Link to comment Share on other sites More sharing options...
.josh Posted August 24, 2006 Share Posted August 24, 2006 first off, did you change "mike" and "brad" to the correct user names? 2nd, try echoing $user to see what it is holding. Quote Link to comment 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.