如何自动发布 php 表单导入的数据

问题描述 投票:0回答:1


1.txt
 aaaaaaaaaa
 bbbbbbbbbb
 cccccccccc
 ......

代码:


`$post_data = array( 'user_data' => array(
'username' => $username,
'password' => $password,
'max_connections' => $max_connections,
'is_restreamer' => $restreamer,
'member_id' => $reseller,
'created_by' => $reseller,
'is_trial' => $is_trial,
'exp_date' => $expire_date,
'bouquet' => json_encode( $bouquet_ids ) ) );

$opts = array( 'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api.php?action=user&sub=create", false, $context ) );
// $obj = $api_result;
// $name = $obj->{'username'};
// $pass = $obj->{'password'};
print_r($api_result);
// print_r($post_data);    
?>

</div>
<div class="content">
<?php
$path = "1.txt";
$file = fopen($path, 'r');
$data = fread($file, filesize($path));
fclose($file);

$lines =  explode(PHP_EOL,$data);
foreach($lines as $line) {
  echo '<form id="submit" action="#add1.php" method="post" >

<div class="form-group">
<div style="width:100%; background:#eeeeee;">
<button type="multiselect" id="submit" class="btn btn-primary" name="submit">ENTER</button>
<input type="hidden" name="macadress" id="macadress" value= '. $line.'>'.$line.'';

  echo '</form>';
}
?>
</div>
<script>
window.onscroll = function() {myFunction()}; // sleep(1);
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;

function myFunction() {
  if (window.pageYOffset > sticky) {
    header.classList.add("sticky");
  } else {
    header.classList.remove("sticky");
  }
}

</script>

大家好

我在运行 php 时使用下面的代码和列出的许多数据。 (1000-1500 pcs)提交行需要一个一个点击

从txt(1.txt)文件导入数据,逐行列出。所有行都有提交按钮并通过单击提交按钮发送。如何以 1 秒延迟自动发布创建的行。

php post foreach submit
1个回答
0
投票

你可以试试这样的脚本。它包括每个 POST 之间的一秒延迟。您需要根据目标服务器对成功调用的响应方式对其进行一些自定义。

注意这是一个命令行脚本——我不会尝试通过网络浏览器运行它,因为如果您有大量记录,它可能会超时。

<?php

// the URL you will be POST-ing to
$url = 'http://somewhere/add1.php';

// the source of your data
$path = '1.txt';

$fh = fopen($path, 'r');
if (!$fh) {
    echo 'Could not open file!' . PHP_EOL;
}

while ($line = trim(fgets($fh))) {

    echo 'Sending ' . $line . '...';
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => [
            'submit' => 'ENTER',
            'macaddress' => $line,
        ],
        CURLOPT_RETURNTRANSFER => true,
    ]);
    $result = curl_exec($ch);

    // check that $result indicates success
    // this will depend on how your endpoint responds
    // example:
    // if ($result == 'OK') {
        echo 'OK' . PHP_EOL;
    // } else {
    //  echo 'FAILED' . PHP_EOL;
    // }
    
    curl_close($ch);

    // wait a second before sending the next one
    sleep(1);
}

fclose($fh);
© www.soinside.com 2019 - 2024. All rights reserved.