【发布时间】:2014-03-23 18:54:26
【问题描述】:
我正在开发一个系统,其中一个 android 应用程序需要定期向服务器发送更新以表明它运行正常。如果 4 次检查通过且未发送更新,则需要发送短信。我想在 PHP 文件中使用一个计数器来检查在没有更新的情况下通过了多少“检查”。然而,每次 android 应用程序联系服务器时,计数器都会重置并且永远不会增加。我让它工作,但我不希望在计数器为 4 之前发送消息。有没有人对如何在文件“重新打开”时保留计数器的值有任何建议。谢谢。
<?php
//...
// check the value sent from the android application
if(isset($_REQUEST['alert'])){
echo "alert";
// everything is ok, reset the counter
$counter = 0;
}
else echo "no alert";
// increase the counter
$counter++;
if($counter >= 4) {
while($row = mysql_fetch_array($result)) {
$phNum = $row['mobile'];
}
// an update has not been sent in 4 attempts, send a text message
send_sms($phNum);
}
//...
?>
【问题讨论】: