Question:
How do I make a page know which user is logged in?
scott k
2011-07-15 19:27:25 UTC
Well I've been learning PHP for a while now and I've made a page to practice with (pretty much looks like facebook :P) and I have a login system going where people can register and login and it all works fine. The home page just shows their name, age, and favorite things. How do I make it to where once a person logs in, the site knows which user is logged in and displays only the content for their account? I'm kind of lost at the moment lol
Three answers:
anonymous
2011-07-16 03:06:26 UTC
When a user tries to log in,



(make a login.php with these)

- take the user name and password via POST

- check these within the database

- if these two matches with the registry, start a session

- save the user name or user id (user id is better since it will be definitely unique) into a session variable

- set a header redirect to actual page like index.php

- in index.php, use that session variable to get specific data from database

- and voila, show what you need to echo in the screen



for reference:

http://php.net/manual/en/ref.session.php
elkins
2016-12-05 12:17:47 UTC
nicely, that relies upon on the way you authenticated the person in the 1st place... in case you used training, you may basically unset() the correct consultation variables. in case you used HTTP authentication, there is not any logging out in it different than by skill of remaining the browser...
Ratchetr
2011-07-15 19:37:53 UTC
Use Sessions.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...