how to check if user is logged in or not?
i have created a simple register and login system using phpmyadmin. On index.html page there are 2 divs. Left and right. On the right div there are 2 forms login and register. Register and login works fine. when user logs in, he is directed to another page.
Now, after login if user comes to index.html page, i need to show him different options in the right div.. like. his dashboard, and more links to his personal account. To do that i changed index.html to index.php and added this code.
But it didn't work. how should i do this?
left div content
if(isset($_SESSION['email']) && isset($_SESSION['pass']))
//show user some links to his account.
//show login and register forms
Is that the entirety of the page? If so, you need to add the session_start() function to the top of the file in order to access the session.
Also, it would help to see the login script as well.
If $_SESSION['pass'] is the user's password, I would recommend not saving it in $_SESSION to begin with, and of course then not checking for it to see if they are logged in. That's one less place a hacker might be able to steal passwords from.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
#1 - I strongly agree with NogDog's suggestion of NOT posting a password in SESSION (!).
MOst importantly thought - whatever do you mean by "it didn't work"? The script died? The php didn't perform as expected? No links showed up?
BTW - try learning to write your code in separate html and php sections. Makes for much easier writing, reading, and understanding the code. Switching in and out of php mode is such a PIA when coding, when reading and when debugging. In this case, just create your html and place a php var in each div. Then in our php area, depending upon your if statements, assign content to the appropriate php var and then let your html (with embedded php vars) simply display the page.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread