如何在URL中读取时间以及如何在URL上书写?

时间:2019-06-12 06:22:07

标签: php mysql

我根据这样的网址创建了QR码

www.sitename.com/index.php?user_idx=1

并阅读此网址的另一个功能。 (因为当我附带此URL时,nodemcu将此链接发送到我的网站,因此user1的值已更改)

但是我想输入ID和时间:

例如

www.sitename.com/index.php?user_idx=1?hh:mm:ss

我想每30秒刷新一次。 我该如何在url上写

每隔30秒阅读一次,该网址必须匹配。

我该怎么做?

编辑1

我尝试了一下,但是没用。

读取功能:

<?php
if(!(  empty($_GET['user_idx']) && empty($_GET['sec']) )){
      $t = time(); // get sec since 1970-01-01
      $t = $t - ($t % 30); // get the closest time divided by 30 sec
      if($_GET['sec'] != $t){
            $user_idx=$_GET['user_idx'];
   require_once 'includes/dbh.inc.php';
   $sql = "UPDATE users SET balance=balance-5 WHERE user_idx='$user_idx';";
   mysqli_query($conn,$sql);
   $results = mysqli_query($conn,"SELECT user_nick FROM users WHERE user_idx= '$user_idx'");
while($row= mysqli_fetch_array($results))
{
$usname= $row['user_nick'];
}
$sql3="INSERT INTO openmv (usr_name,pass_time,usr_idx) values ('$usname',NOW(),'$user_idx')";
mysqli_query($conn,$sql3);

}

      }


?>

写功能:

}   else if (isset($_SESSION['userID'])) {
              if(($balance>=5)){
                  $t = time(); // get sec since 1970-01-01
                  $t = $t - ($t % 30); // get the closest time divided by 30 sec
                  if(($_GET['sec'] != $t))
                   $text="http://sitename.com/project/index.php?user_idx={$_SESSION["userID"]}&sec=$t";
            echo '<div class="alert alert-success" role="alert">
 Başarılı bir şekilde giriş yaptınız.
</div>';
               QRcode::png($text,$file,'L',10,2);
            echo "<center><img src='".$file."'></center> " ;  
              }
              else if($balance < 5){
                  echo '<div class="alert alert-danger" role="alert">
Kartınızda bakiye yok lütfen yükleme yapınız !</div>
<a href="balance_info.php"><button type="submit" class="btn btn-primary">Para yükle</button></a>

';
              }



}

失败

例如时间1560323000 当我去 sitename.com/project/index.php?luser_idx=1&sec=1560323000  任何变化都请帮助我

1 个答案:

答案 0 :(得分:1)

使用&组合URL ?user_idx=1&sec=1560321720中的多个参数。搜索query string以获得更多详细信息。

用于生成网址

$t = time(); // get sec since 1970-01-01
$t = $t - ($t % 30); // get the closest time divided by 30 sec
$url = 'www.sitename.com/index.php?user_idx=1&sec='.$t;  
echo($url);

要阅读网址

$t = time(); // get sec since 1970-01-01
$t = $t - ($t % 30); // get the closest time divided by 30 sec
if($_GET['sec'] == $t){
    return false; // if they are same, return false and change nothing.
}else{
    return $new_data; // return new data.
}