簡體   English   中英

使用cron作業自動提交表單

[英]Auto-submit form using cron job

當我使用Web瀏覽器執行代碼時,我的代碼運行良好,但是當我嘗試使用wget,curl或python腳本執行代碼時,它無法正常工作。 將執行php代碼,但不會自動提交表單。

<?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>

還嘗試在javascript中:

<script type="text/javascript">
        document.forms["f"].submit();
      </script>

但結果相同。

使用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);

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM