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

huangapple go评论54阅读模式
英文:

How to auto post php form imported data

问题

以下是您要翻译的内容:



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

Code:


`$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>

Hello all.

I use below code and many data listed when run php. (1000-1500 pcs) need to click one by one for submit lines.

imported data from txt (1.txt) file and listed line by line. all lines have submit button and send by click submit button. How to auto post created lines with 1 second delay.

英文:


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

Code:


`$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>

Hello all.

I use below code and many data listed when run php. (1000-1500 pcs) need to click one by one for submit lines.

imported data from txt (1.txt) file and listed line by line. all lines have submit button and send by click submit button. How to auto post created lines with 1 second delay.

答案1

得分: 1

以下是您要翻译的内容:

你可以尝试类似这样的脚本。它在每次POST请求之间包括一秒的延迟。根据您的目标服务器对成功调用的响应方式,您需要稍微定制它。

注意:这是一个命令行脚本,我不建议通过Web浏览器运行它,如果您有大量记录,可能会超时。


// 将要POST到的URL
$url = 'http://somewhere/add1.php';

// 数据源
$path = '1.txt';

$fh = fopen($path, 'r');
if (!$fh) {
    echo '无法打开文件!' . PHP_EOL;
}

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

    echo '正在发送 ' . $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);

    // 检查$result是否表示成功
    // 这将取决于您的端点如何响应
    // 示例:
    // if ($result == 'OK') {
        echo 'OK' . PHP_EOL;
    // } else {
    //  echo 'FAILED' . PHP_EOL;
    // }
    
    curl_close($ch);

    // 在发送下一个请求之前等待一秒
    sleep(1);
}

fclose($fh);

希望这有所帮助!如果您需要进一步的帮助,请告诉我。

英文:

You could try a script something like this. It includes a one second delay between each POST. You would need to customise it a little depending on how your destination server responds to a successful call.

NB this is a command line script - I wouldn't attempt to run it via a web browser as it will likely time out if you have a large number of records.

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

答案2

得分: 1

你真棒。逐行发送,但无法从数据页面接收行。

> ($username = $_POST['macadress'];)

英文:

You are awesome. Its sending lines one by one. but can not received line from data page.

> ($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 ) );   
?>

huangapple
  • 本文由 发表于 2023年5月10日 17:40:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216940.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定