开发者

PHP Cookie management

here is what my client requirements are:

1> There is a common web page that lets each of the customer login. On successful login, a cookie is created and the customer is redirected to a "Waiting area" page. I need to create a cookie that would last for 10 secs and keep refreshing the time until the customer has closed the window.

2> The admin page will list all the customers who have not yet closed the "Waiting area" page and are waiting on the admin to move forward.

Since I am new to session and cookie management, I am not sure exactly wh开发者_运维百科at needs to be done here i.e. use session_start or setcookie ? Since the admin needs a list of all customers waiting, I guess all these entries need to go in a database table? And whenever a customer closes the page, the entry should be deleted from the database.

Is my understanding correct? If anyone has better suggestions, please let me know.


I would advise to use the session_start functionality and keep the users associated with their session ID in a database. In the session table you keep track of the created timestamp and can easily check which users are waiting using a single query.

If you implement it only cookie based, you will not know who waits, because this information is only client based.


If you make it database related, this means you will need to update table every second. If you decide to go with that, you can create a simple table which holds session ids, end_time.

To avoid the every second connection to the db, I would suggest when admin clicks on let's say viewSessions.php on top of that script to have a single query which deletes all sessions which should be deleted - DELETE FROM my_sessions WHERE end_time<=(DATE_SUB(now(), INTERVAL 10 SECOND));


Your requirements are strange, I cannot figure out why any user would "wait" on a "Waiting area" page. I would rethink the 10 sec. cookie part.

For data persistance, I would recommend you use sessions as they are pretty easy to integrate to that type of context.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜