简体   繁体   English

PHP跟踪当前用户

[英]PHP Tracking current users

I have an website with editable databases. 我有一个带有可编辑数据库的网站。 I am trying to implement a simple system that ensures no one is editing the same row at the same time. 我正在尝试实现一个简单的系统,以确保没有人同时编辑同一行。 I cannot find any information on how to pass PHP variables to different users or how to store them globally on the server. 我找不到有关如何将PHP变量传递给不同用户或如何将它们全局存储在服务器上的任何信息。

Ex: User 1 is editing Row ABC

User 2 attempts to edit Row ABC

User 2 is warned that someone is editing Row ABC

The ideal solution in my mind is 我心中理想的解决方案是

User 1 is editing Row ABC -> Create PHP var for that row to lock it

User 2 attempts to edit Row ABC -> A check is done to see if that PHP var exists and its state (0/1)

How can I pass this value across to different browser sessions and/or users? 如何将该值传递给不同的浏览器会话和/或用户?

You don't need to use PHP vars for this. 您不需要为此使用PHP var。 Just store in the database which row is being edited by which user. 只需将哪个用户正在编辑的行存储在数据库中即可。 When a user starts editing a row. 用户开始编辑行时。

Implement it with a table called RowLock and give it 2 columns, RowId and UserId . 用一个名为RowLock的表实现它,并给它2列RowIdUserId Editing a row is: 编辑一行是:

  • Checks if the row is being edited by another user, 检查该行是否正在由其他用户编辑,
  • If it is, access is denied 如果是,则拒绝访问
  • If it isn't, put the user id in the RowLock table and then grant access 如果不是,请将用户标识放在RowLock表中,然后授予访问权限

When they are finished editing the row, UserId is set to null or the the lock is deleted entirely. 当他们完成对行的编辑后, UserId将设置为null或将锁完全删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM