e4games Posted July 27, 2009 Share Posted July 27, 2009 So I got register done for my site (I think) and so I was wondering how to make a code that only shows up if your logged in Link to comment Share on other sites More sharing options...
Kon-Tiki Posted July 28, 2009 Share Posted July 28, 2009 So I got register done for my site (I think) and so I was wondering how to make a code that only shows up if your logged inDo the following:When the user arrives at the site, show the login page.If the user logs in, check and clean the input.Check database for matching login/password combo.If the returning result is 1 (shouldn't be able to have any more matches than just 1!), set a session var containing the login name / login ID (whichever works best for you)If not, call the login page (function is easiest if you code like me, but it's down to personal style) again with an error.My login code usually looks like this:if (!isset($_SESSION["login"])) login(); // Contains the login form, with either a call to processing the input in the beginning, or just processes the input before placing the formelse {// All other code/function calls here} Link to comment Share on other sites More sharing options...
e4games Posted July 28, 2009 Author Share Posted July 28, 2009 ok, thanks...but my question is once they login in how do you make sure that the page is protected so only people who login can view the page?? Link to comment Share on other sites More sharing options...
Synook Posted July 30, 2009 Share Posted July 30, 2009 You have a conditional that checks whether the login session var is set, and if it is, you display the page, if it isn't you redirect them to login. Link to comment Share on other sites More sharing options...
Kon-Tiki Posted July 30, 2009 Share Posted July 30, 2009 That's what that if-block and that session var are for. The session var keeps in mind that that person is logged in at that moment. It'll end once he closes the browser.The if-block sees whether or not that person is logged in. If they aren't, they just won't get through that block. Link to comment Share on other sites More sharing options...
e4games Posted July 31, 2009 Author Share Posted July 31, 2009 I don't get it...I checked a bunch of places to see if I could figure it out and I can't...I don't get the code that makes it show certain pages... Link to comment Share on other sites More sharing options...
justsomeguy Posted July 31, 2009 Share Posted July 31, 2009 You don't have code that makes it show a page. You have code that redirects you if you're not logged in. That's all it is, one little if statement with a call to the header function to redirect if the check fails. if (!$logged_in){ header('Location: login.php'); exit();} I'll leave it up to you to fill in the details. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.