2013-07-08 84 views
0

我想这个代码刷新本身&将数据发布到sendingms.php但不应该重定向并保留在这个page.tus每次刷新它下载新的数据并发布到sendingms.php。 PLZ建议我任何想法?刷新页面,每次刷新时都应该发布数据?

<?php 
    $page = $_SERVER['PHP_SELF']; 
    $sec = "15"; 
    header("Refresh: $sec; url=$page"); 
    $url=$_REQUEST['url']; 
     $ch = curl_init(); 

     curl_setopt($ch, CURLOPT_HEADER, 0); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

    $html= curl_exec($ch); 
     curl_close($ch); 

    //parsing begins here: 
    $doc = new DOMDocument(); 
    @$doc->loadHTML($html); 
    $nodes = $doc->getElementsByTagName('title'); 

    //get and display what you need: 
    $title = $nodes->item(0)->nodeValue; 
    $first = current(explode("|", $title)); 

    $to="888888888"; 
    header('Location: sendsms.php?to=' .$to .'&sms=' .$first); 

    ?> 
+0

使用cURL在sendms.php上发布数据 – Fallen

回答

0

我建议通过crontab运行它。

你有两个选择,第一个是更好:

  1. 服务器作为一个shell脚本直接运行文件。
  2. 使用curl或wget访问Web服务器上的文件。

第一种方案会是这个样子:

* * * * * /usr/bin/php /my/home/path/script.php 

第二种情况是相似的:

* * * * * curl http://example.com/path/to/file/script.php 

这不是你要的到底是什么,当然。如果你希望这个页面简单地坐在一个网络浏览器并重新加载每n秒,你可以使用JavaScript和jQuery的一些AJAX:

<script type="text/javascript"> 
var timer = setInterval(function() { 
    $.post('/sendsms.php', { data: yourdata }, function (data) { 
    console.log(data); 
    }); 
}, 15000); 
</script> 

希望这有助于!

0

任何标准刷新都不会重新发布数据。根据浏览器的不同,它可能会发出一个正常的GET请求,或者浏览器会要求您确认POST数据重新提交。

您可以通过在html中创建表单并在POST数据中将所需的所有变量添加到该表单中来执行所需操作,如< input type =“hidden”>。然后,您可以使用JavaScript提交该表单(在所需延迟之后 - 15秒内)。