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

5tmbdcev  于 2023-05-16  发布在  PHP
关注(0)|答案(2)|浏览(107)
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个)需要逐个点击提交行。
从txt(1.txt)文件导入数据并逐行列出。所有行都有提交按钮,并通过单击提交按钮发送。如何以1秒延迟自动过帐创建的行。

1szpjjfi

1szpjjfi1#

你可以试试这样的脚本。它包括每次开机自检之间的一秒延迟。您需要根据目标服务器对成功调用的响应方式对其进行一些自定义。
注意,这是一个命令行脚本--我不会试图通过Web浏览器运行它,因为如果你有大量的记录,它可能会超时。

<?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);
avwztpqn

avwztpqn2#

你太棒了它的发送线路一条接一条。但不能从数据页接收行。
($username = $_POST ['macadress'];)

<?php
$panel_url = 'http://send_data_to_server/';
$username = $_POST['macadress'];
$password = 'Pop';
$max_connections = 1;
$restreamer = 0; //allow restream 0 no 1 yes
$reseller = 2; //set with reseller id
$is_trial = 0; //set 0 or 1

$bouquet_ids = array(2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18 );//add bouquet id
$expire_date = strtotime( "+15 month" );
###############################
$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 ) );   
?>

相关问题