我有一个生成器脚本,它基本上生成随机令牌并将它们存储在MySQL数据库中。有几个人会使用它,而我想做的事情基本上显示生成的令牌,这些令牌只是在生成页面上生成的,这样当它们生成令牌并且它们都与其他令牌混淆时,他们可以轻松地复制它们生成的令牌而无需通过每个人的代币的整个表格。
我已将整个表单和脚本放在这里,提交部分工作正常,只是想知道这个额外的功能,如果它是可能的。
<?php
function randString($length, $charset='ABCEFGHJKLMNPRTUVWXY23456789' )
{
$str='' ;
$count=strlen($charset);
while ($length--) {
$str.=$charset[mt_rand(0, $count - 1) ];
}
return $str;
}
if (isset($_POST[ 'create'])) {
$token_semi_quantity=0 ;
$token_combo=$ _POST[ 'howmany'];
$seller=$_POST[ 'seller'];
while ($token_semi_quantity < $token_combo) {
$token=randString(4) . "-" . randString(4) . "-" . randString(4);
$token_semi_quantity++;
$token_info=$_POST[ 'tokeninfo'];
$token_explode=e xplode( ',', $token_info);
$token_time=$token_explode[0];
$token_desc=$token_explode[1];
$NowDateTime=date( "Y-m-d H:i:s");
// Log dat shit
$WhoGenDatToken=$userRow[ 'username'] . ' Generated Token <b>' . $token . '</b> at ' . date( "m-d-Y h:i") . ' CST.';
$gen_token=new CONNECT;
$insert_token=( "INSERT INTO `tokens`
(`id`, `token`, `time`, `generatedby`,
`timegenerated`, `used`, `seller`,
`description`)
VALUES ('NULL', :generatetokenVal,
:generatetokentimeVal, :generatetokenadminName,
:generateDateTime, '0',
:generatetokenSeller, :generatetokenDesc);
INSERT INTO `admin_act` (`activity`)
VALUES(:WhoGenDatTokenDen)");
$stmt=$gen_token->runQuery($insert_token);
$stmt->execute(Array( ':generatetokenVal' => $token,
':generatetokentimeVal' => $token_time,
':generatetokenadminName' => $adminName,
':generateDateTime' => $NowDateTime,
':generatetokenSeller' => $seller,
':generatetokenDesc' => $token_desc,
':WhoGenDatTokenDen' => $WhoGenDatToken ));
}
}
?>
<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
<div class="row">
<h2> <span class="fa fa-tags"></span> <?php
echo $xblsname; ?> Token Generator</h2>
<div class="col-md-12">
<div class="panel panel-default tabs">
<div class="panel-body tab-content">
<div class="tab-pane active" id="tab-first">
<div class="col-md-3">
<h3><?php
echo $xblsname; ?> Token Generator</h3>
<form method="POST" class="form-horizontal">
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label">How Many?</label>
<div class="col-md-6 col-xs-12">
<select class="form-control select" name="howmany">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
<span class="help-block">Choose how many to generate</span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label">Token Type</label>
<div class="col-md-6 col-xs-12">
<select class="form-control" name="tokeninfo" id="tokeninfo">
<option value="1,1 Day Server Time">1 Day Server Only</option>
<option value="3,3 Days Server Only">3 Days Server Only</option>
<option value="7,1 Week Server Only">1 Week Server Only</option>
<option value="14,2 Weeks Server Only">2 Weeks Server Only</option>
<option value="31,1 Month Server Only">1 Month Server Only</option>
<option value="110,1 Day with GTA Menu">1 Day with GTA Menu</option>
<option value="111,3 Days with GTA Menu">3 Days with GTA Menu</option>
<option value="112,1 Week with GTA Menu">1 Week with GTA Menu</option>
<option value="113,2 Weeks with GTA Menu">2 Weeks with GTA Menu</option>
<option value="114,1 Month with GTA Menu">1 Month with GTA Menu</option>
<option value="999,Custom Token 1">Custom Token 1</option>
</select>
<span class="help-block">Choose token value</span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-xs-12 control-label">Seller</label>
<div class="col-md-6 col-xs-12">
<select class="form-control" name="seller">
<?php // Don 't change the options here - do it in includes/settings.php -JohnC
if (!empty($seller1)) print "<option value=\"" . $seller1 . "\">" . $seller1 . "</option>";
if (!empty($seller2)) print "<option value=\"" . $seller2 . "\">" . $seller2 . "</option>";
if (!empty($seller3)) print "<option value=\"" . $seller3 . "\">" . $seller3 . "</option>";
if (!empty($seller4)) print "<option value=\"" . $seller4 . "\">" . $seller4 . "</option>";
if (!empty($seller5)) print "<option value=\"" . $seller5 . "\">" . $seller5 . "</option>";
if (!empty($seller6)) print "<option value=\"" . $seller6 . "\">" . $seller6 . "</option>";
if (!empty($seller7)) print "<option value=\"" . $seller7 . "\">" . $seller7 . "</option>";
if (!empty($seller8)) print "<option value=\"" . $seller8 . "\">" . $seller8 . "</option>";
if (!empty($seller9)) print "<option value=\"" . $seller9 . "\">" . $seller9 . "</option>";
if (!empty($seller10)) print "<option value=\"" . $seller10 . "\">" . $seller10 . "</option>";
if (!empty($seller11)) print "<option value=\"" . $seller11 . "\">" . $seller11 . "</option>";
if (!empty($seller12)) print "<option value=\"" . $seller12 . "\">" . $seller12 . "</option>";
if (!empty($seller13)) print "<option value=\"" . $seller13 . "\">" . $seller13 . "</option>";
if (!empty($seller14)) print "<option value=\"" . $seller14 . "\">" . $seller14 . "</option>";
if (!empty($seller15)) print "<option value=\"" . $seller15 . "\">" . $seller15 . "</option>";
?>
</select>
<span class="help-block">Choose seller</span>
</div>
</div>
</div>
<div class="panel-footer">
<button name = "create" class="btn btn-primary pull-right">Generate Token(s) <span class="fa fa-magic fa-right"></span></button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
感谢先进的任何帮助。
答案 0 :(得分:1)
在while
循环内,将令牌存储到数组/集合/列表
// inside while loop, after $token = ...
$generatedtoken[] = $token;
然后你想在哪里展示/列出它们:
foreach($generatedtoken as $token) {
echo $token; // some markup maybe added
}
追加到一个不被认为是数组的var(可能)是脏的,所以在if
或适当的地方之前,实例化数组。
$generatedtoken = array();