使用cron作业的自动提交表单

2024-09-27 07:33:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码在使用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中尝试过:

^{pr2}$

但结果是一样的。在


Tags: 代码textformhttpurlhtmlwwwtype
1条回答
网友
1楼 · 发布于 2024-09-27 07:33:17

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

?>

相关问题 更多 >

    热门问题