我正在构建一个CMS/CRM,并希望让用户使用他们的数据库在他们的服务器上安装这个软件。
我想要跟踪该安装的一些数据,比如版本,这样我就可以在该安装过期时发送更新。比如当Wordpress告诉你有新版本可用时。
我还希望能够跟踪用户的数量,以便能够为安装收费。
我正在使用PHP, MySQL(PDO).
你能告诉我这个过程叫什么吗?任何关于这个过程的参考都将是非常棒的。
在你的应用程序中,你可能有一个数组的数据,你想跟踪;像这样
$data = array(
'domain' => 'http://example.com',
'version' => '1.4.35',
'date_added' => '2014-08-20',
'last_update' => '2014-08-22'
);
然后你可以发送一个请求到你的服务器,看看是否有什么新的;使用cURL或任何其他方法发送HTTP请求
$curl = curl_init("http://your-server.com/your-service/");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); // convert it to JSON format
$json = curl_exec($curl);
curl_close($curl);
// this is your feedback, in JSON format
$response = json_decode($json, true);
像这样检查状态是好的,但是在curl_close()
调用之前
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($status == 201){
// ... all fine
}else{
// otherwise, do something but don't use exit() or die() in this case
}
解码后的$response
值可能看起来像这样
array(
'some_key' => 'some_value',
'another_key' => 'another_value'
...
);
现在,根据响应,向用户回显一条消息,如下所示
if(isset($response['some_key']) && $response['some_key'] == 'some_value')){
echo "An update is out there, <a href='"http://your-domain.com/update'">Check it out</a>";
}