mirror of
https://github.com/ZeroDream-CN/SakuraPanel.git
synced 2025-01-12 01:42:52 +08:00
Tool: Generate random invite code
可以随机生成指定数量的邀请码并储存到数据库
This commit is contained in:
parent
de97c5f5a6
commit
363774138a
30
gencode.php
Normal file
30
gencode.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
if(php_sapi_name() !== "cli") {
|
||||
exit("This program only can running on cli mode");
|
||||
}
|
||||
if(!file_exists("configuration.php")) {
|
||||
exit("未找到 configuration.php,请放在网站根目录运行\n");
|
||||
}
|
||||
function getRandomText($length) {
|
||||
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
|
||||
$texts = "";
|
||||
for($i = 0;$i < $length;$i++) {
|
||||
$texts .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||||
}
|
||||
return $texts;
|
||||
}
|
||||
include("configuration.php");
|
||||
echo "请输入要生成的邀请码数量> ";
|
||||
$num = trim(fgets(STDIN));
|
||||
$conn = mysqli_connect($_config['db_host'], $_config['db_user'], $_config['db_pass'], $_config['db_name'], $_config['db_port']);
|
||||
if(preg_match("/^[\d]{1,8}$/", $num)) {
|
||||
$num = Intval($num);
|
||||
for($i = 0;$i < $num;$i++) {
|
||||
$code = getRandomText(32);
|
||||
mysqli_query($conn, "INSERT INTO `invitecode` (`code`, `user`) VALUES ('{$code}', NULL)");
|
||||
echo "已添加:{$code}\n";
|
||||
}
|
||||
exit("已生成指定数量激活码至数据库!\n");
|
||||
} else {
|
||||
exit("数量不合法\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user