使用cron作业自动提交表单

时间:2017-11-06 14:03:34

标签: javascript php python cron

当我使用Web浏览器执行它时,我的代码运行良好,但是当我尝试使用wget,curl或python脚本执行它时,它无法正常工作。 执行php代码,但表单不是自动提交的。

loff_t read_pos = 0, write_pos = 0;
size_t data_sz = 0;

DECLARE_WAIT_QUEUE_HEAD(wq);

static ssize_t
my_read(struct file *file, char __user *buf, size_t lbuf, loff_t *ppos)
{
   int nbytes;
   spin_lock(&wq.lock); // Take the lock before checking condition
   // Next call will drop the lock while waiting and reacquire it on wake up.
   wait_event_interruptible_exclusive_locked(&wq, data_sz >= 512);
   // TODO: Interruptible wait may wakeup premature; check its return value.
   data_sz = -1; // Prevent other waiters to enter read/write section
   spin_unlock(&wq.lock);

   nbytes = simple_read_from_buffer(buf, lbuf, &read_pos, my_buff, my_buff_size);
   *ppos = read_pos;

   spin_lock(&wq.lock); // Take the lock before updating data_sz
   data_sz = write_pos - read_pos;
   // There is no 'wake_up_interruptible_locked',
   // but "normal" wakeup works with interruptible waits too.
   wake_up_locked(&wq);
   spin_unlock(&wq.lock);

   return nbytes;
}

也在javascript尝试过:

<?php
$dbh = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');

$reponse = $dbh->query('SELECT code FROM download limit 1');
$donnees = $reponse->fetch();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
   <title>validation de formulaire</title>
   <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
   <style type="text/css">
   </style>
</head>
<body onload="document.f.submit()">
  <form name="f" method="post" action="http://website.lol/upload/traitement.php">
    <input type="text" class="form-control" id="url" name="url" placeholder="http://..." value="https://url.com/<?php echo $donnees['code']; ?>">
  </form>
</body>
</html>

但结果相同。

1 个答案:

答案 0 :(得分:0)

使用curl发布数据

<?php

$url = 'http://website.lol/upload/traitement.php';

$fields = array(
   'url' => urlencode("your_values_here"),
);

//url-ify the data for the POST
 foreach($fields as $key=>$value) { 
    $fields_string .= $key.'='.$value.'&'; 
 }
 rtrim($fields_string, '&');

 //open connection
 $ch = curl_init();

 //set the url, number of POST vars, POST data
 curl_setopt($ch,CURLOPT_URL, $url);
 curl_setopt($ch,CURLOPT_POST, count($fields));
 curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

 //execute post
 $result = curl_exec($ch);

 //close connection
 curl_close($ch);

?>