Jump to content

Login


e4games

Recommended Posts

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
Do 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

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

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

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

Archived

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

×
×
  • Create New...