【问题标题】:Periodically sending vars to PHP page automatically定期自动将 vars 发送到 PHP 页面
【发布时间】:2011-08-03 19:08:22
【问题描述】:

每 4 秒我刷新一个 php 页面并更新时间。 每次发生这种情况时,我都想将时间发送到另一个页面,但不要离开该页面 真是让人耳目一新……

下面是一些示例代码:

<?

$target = mktime(10, 0, 0, 0, 0, 0) ;
header('refresh:4; url=timer.php');
$today = (int)(time ());

$siteToReceiveTime = "http://www.nbit.co.za/toriggo/receive.php?time=$today";

print "time in $today seconds";

?>

【问题讨论】:

  • 为什么不直接存储到数据库中呢?

标签: php timer refresh


【解决方案1】:

有几种方法可以做到这一点... Ajax 就是其中之一——它可以处理每 4 秒的位,并且能够在不更改页面的情况下发出请求。 另一种选择是php curl...

【讨论】:

    【解决方案2】:

    阅读CURL function documentation。您可以让 PHP 调用 CURL 从 PHP 脚本中为您加载页面,而不会干扰您的用户。

    【讨论】:

      【解决方案3】:
      file_get_contents("http://www.nbit.co.za/toriggo/receive.php?time=$today");
      

      【讨论】:

        猜你喜欢
        • 2015-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多