简体   繁体   中英

Auto-submit form using cron job

My code works well when I execute it with a web browser, but when I try to execute it with wget, curl or a python script, it doesn't work correctly. The php code is executed, but the form is not auto submited.

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

Also tried in javascript :

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

But same result.

Post data using 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);

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM