stelthius Posted January 8, 2008 Share Posted January 8, 2008 ok what i want to accomplish, i have a bunch of pages i want to protect with a login system, but i dont want people to be able to access these pages without being logged in so say for instance they logged in and went to page www.mysite.com/page3.html and then logged out and went to www.mysite.com/page3.html i want it to some how say you need to login and not let them view the pages untill they do login, im not a pro im a very very new to php so any help or advice is very much appretiated. thanks Rick Quote Link to comment Share on other sites More sharing options...
trq Posted January 8, 2008 Share Posted January 8, 2008 Have you tried googling? The subject of php login scripts has been covered many, many times before. Quote Link to comment Share on other sites More sharing options...
stelthius Posted January 8, 2008 Author Share Posted January 8, 2008 yeah i google, i tried googling php and user sessions but i didnt know if that was the correct term for it Quote Link to comment Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 yeah i google, i tried googling php and user sessions but i didnt know if that was the correct term for it try to google for "php login script" i hope you will find nice articles and classes for you. Quote Link to comment Share on other sites More sharing options...
p2grace Posted January 8, 2008 Share Posted January 8, 2008 Basically upon logging in you create a $_SESSION variable (or a $_COOKIE, but if you don't want the variables to last longer than the browser is open I'd recommend using $_SESSION because they're more secure) and then each page checks to make sure those $_SESSION variables exist. Very basic example: Upon logging in you'd do this: // Assuming you've already validated their login $_SESSION['userid'] = $userid; // Where the userid is the id of the user (the id could be their username or the row id in database table for the given user) $_SESSION['authlevel'] = $authlevel; // If you want to only show certain sections of the page based on permission level you'd use something like this At the top of each page you'd do something like this: // For making sure they're logged in do the following, make sure you do this before the headers have been sent (before any html code) if(!isset($_SESSION['userid'])){ header("Location: login.php"); } // put html code here, they'll have to be logged in to view it // For making sure they have needed permission levels to view the following content, this does not have to be before the headers, // it can be anywhere on the page where you wish to restrict permissions if($_SESSION['authlevel'] == 2){ // show level 2 permission content } This is a very basic example, but the concept is there. Let me know if you need further details. Quote Link to comment Share on other sites More sharing options...
stelthius Posted January 8, 2008 Author Share Posted January 8, 2008 Thanks p2grace that was the little bit of help i was looking for just a nudge in the right direction, thank you 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.