这可以用 PHP 实现吗?

发布于 2024-09-30 14:07:29 字数 355 浏览 0 评论 0原文

我创建了一个适用于不同会话的网站,每个用户在 mydomain.com/user 都有自己的页面。我想知道如果一个用户从他的帐户登录并单击一个按钮,是否有可能在按钮指定用户的仪表板上显示一个 HTML 框?

当目标用户登录时,他应该能够从他的帐户中看到该框。

我将指定该框应出现在按钮中的仪表板上的用户名。

假设 - 我有 4 个按钮,名称分别为 1b、2b、3b、4b。

如果用户单击 1b,它应该在用户 a 的仪表板上显示一个框。如果他点击 b2,它应该在仪表板或用户 b 上显示一个框等等......

这可能吗?这就像 Facebook 的即时好友请求功能。如果是的话,请你们给一些提示。

谢谢

I have created a website that works with different sessions and every users has his own page at mydomain.com/user . I want to know that is it possible that if one user logs in from his account and clicks on a button, it displays a HTML BOX on the dashboard of the button specfied user?

When the intended user logs in, he should be able to see the box from his account.

I would specify the username on whose dashboard the box should appear in the button.

Say - I have 4 buttons named 1b, 2b, 3b, 4b.

If user clicks on 1b, it should display a box on the dashobard of user a. if he clicks on b2, it should display a box on the dashbaord or user b and so on.....

Is this possible? It's like Facebook's instant friend request feature. If yes, can you guys plz give some hint.

Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三人与歌 2024-10-07 14:07:29

要执行类似的操作,您需要一种方法来存储要向用户显示的消息(框)(使用包含与用户关联的消息的数据库是最简单的)。按下按钮的操作将在那里添加数据。
此操作可以通过带有 POST 方法的简单表单或通过 Ajax 查询来完成。

然后,您可以在用户登录或刷新仪表板时检查是否有新消息。您只需要检查数据库,获取消息并将其删除(或将布尔值“已收到”设置为 true)。这是纯 PHP,不是即时的(仅在登录或页面刷新时)。
使用此技术,您可以在将块发送到客户端之前将其插入 HTML 中。

最后,如果你想要即时通知,你应该准备一个javascript来定期查询新消息。在服务器端,您有一个 PHP 脚本在数据库中查找并返回消息数据。
使用此技术,您发送不带块的页面,并且您有另一个请求来获取该块,然后使用 javascript 将其添加到 HTML。

一些有用的链接:

To do something like that, you need a way to store the messages (boxes) you want to show to the users (using a database with messages associated to users is the easiest). The action of the pressed button would add data there.
This action can be done via a simple form with POST method or via an Ajax Query.

Then, you can check if there are new messages for an user when he/she logs in or refreshes his/her dashboard. You just need to check the database, take the message and remove it (or set a boolean "received" to true). This is pure PHP and not instant (only on login or page refresh).
With this technique, you insert the block in the HTML before sending it to the client.

Finally, if you want instant notification, you should prepare a javascript to do queries for new messages regularly. On the server side, you have a PHP script looking in the database and returning the message data.
With this technique, you send the page without the block and you have another request to get the block and then add it to the HTML with javascript.

Some useful links:

别在捏我脸啦 2024-10-07 14:07:29

纯粹的 PHP,不是真的。这类事情就是你需要 JavaScript 的地方。当用户a点击b2时,他们会向服务器发出后台请求,服务器记录有一条消息正在等待用户b。然后,您需要从用户 b 的浏览器发出定期请求,检查是否有新消息可用。如果是,则向用户显示该框。

Pure PHP, not really. This sort of thing is where you'll need JavaScript. When user a clicks on b2, they'll make a background request to the server, which records that there's a message waiting for user b. Then you'll need a periodic request to go out from user b's browser that checks to see if there are new messages available. If so, display the box to the user.

吖咩 2024-10-07 14:07:29

是的,可以这样做。

例如,您可以创建一个表作为此类消息的“缓冲区”。
仪表板或用户登录的任何页面都可以有一个小的 ajax 脚本,该脚本会不时检查该表,并传递消息(如果登录用户存在消息)。

Yes, it is possible to do so.

You could create, for example, a table that would serve as a 'buffer' for that kind of messages.
Dashboard or any page where user is logged in could have a little ajax script that would check that table from time to time, and deliver messages if they exist for the logged in user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文