# Solved: User Interface



## pcpro17 (Oct 9, 2006)

Hello. I'm coding a user interface (register, login, control panel, access to login-only pages, etc., etc.) for my website using MySQL, PHP, JavaScript, and cookies. There are two problems that have me a little stumped:


What is the recommended or best-practice way of determining if a user is currently logged in? I could update a DATETIME field in the user record each time a page is accessed, but this seems really cumbersome. There has got to be a more elegant way to do this. In the phpMyAdmin interface I noticed an ON UPDATE CURRENT_TIMESTAMP attribute that looks promising, but when I try to use it I get an error:


> Error
> 
> SQL query:
> 
> ...



The other issue I am running into is let's say a user checks the box to "Remember Me" when he logs in. This causes cookies to be set with, for example, user name, id, password, etc., etc.. Now, let's say the user bookmarks a page that is only visible if you're logged in, but since it's been a while since the last visit to the site the POST data that is used to maintain the login between page transisions is long lost, resulting in the user being promted to login again. Is the only way to handle this with an auto-refresh? That is, the pages is loaded, the cookies are read, and user data is re-submitted via POST to server for handling by PHP script?

Thanks.:up:


----------



## Eriksrocks (Aug 7, 2005)

Use PHP sessions:
http://www.tizag.com/phpT/phpsessions.php

A basic example of how to create a login system with sessions:
http://www.htmlite.com/US001.php


----------



## pcpro17 (Oct 9, 2006)

Hi Erik. Thanks for the tip! It looks like PHP sessions are very useful, and I see how I can use them to resolve item one. However, I don't think they'd work for item two (i.e. where a user returns to a bookmarked page that requires login to view). In that case do you think the best alternative is to have the variables set in cookies and use auto-refresh to retrieve them?
Thanks!


----------



## colinsp (Sep 5, 2007)

Another useful tutorial and login script *here* that may be of help.


----------

