将数据从一个 php 页面发送到另一个 php 页面,并使用新数据刷新它


Send data from one php page to another and refresh it with the new data

我正在尝试以下内容:

我有 1 个页面称为请求.php它接收来自 hipmob 网络钩子的帖子

文档:https://www.hipmob.com/documentation/chat-events.html

<?php
$entityBody = file_get_contents('php://input');
$post_data = $_POST;
$data = json_encode($post_data, JSON_PRETTY_PRINT);
$file = 'webhook.txt';
$current = file_get_contents($file);
file_put_contents($file, $data);
//error_log($data);
?>

示例输出:

    {
    "app": "eba978375b294260bd884a72afd5eb75",
    "appname": "Worten Suporte",
    "event": "chat.message",
    "started": "2015-06-12T08:32:56+00:00",
    "ip": "62.28.231.158",
    "platform": "Windows'/Chrome",
    "version": "43",
    "timestamp": "2015-06-12T09:32:36+00:00",
    "body": "mensagem",
    "properties": "{'"as'":'"text'"}",
    "id": "70acc6b20cbc44f18f99e2e922130904",
    "email": "eba978375b294260bd884a72afd5eb75.70acc6b20cbc44f18f99e2e922130904@app.hipmob.com",
    "visits": "1",
    "locale": "pt",
    "userdata:context": "viewing file:'/'/'/C:'/Users'/hp'/Desktop'/chattest.html title: ;url: file:'/'/'/C:'/Users'/hp'/Desktop'/chattest.html",
    "state": "",
    "signature": "622869e9210ba4599e95322cafd7f8123552375b44314e502ceb53972f9bfadb1a49d965f3102d8f30028690bc606632c6878e4ff95003ec15c0ea2749a8bd84"
}

想知道是否可能每次我在此页面收到帖子时,我都会在其他页面收到通知,例如:

示例.php

并使用新数据刷新它

为此,您需要使用可见性标志维护最后插入的行。

之后,您必须在特定间隔后使用 settimeout 调用 ajax(例如.php)。在该 ajax 调用中,您可以比较可见性标志并刷新页面。

你应该把你从hipmob收到的数据存储在一个数据库中,让我们说一个标志"看到"。

然后,您可以从示例.php页面创建 AJAX 调用,以获取数据库中尚未看到的通知,并基于该通知刷新数据。