给我一个卡密验证管理的php项目源码
时间: 2024-02-18 19:05:12 浏览: 348
一套php写的比较完善的卡密验证系统,后台功能完善。
4星 · 用户满意度95%
以下是一个简单的卡密验证管理的 PHP 项目源码,包括了用户登录、卡密生成、卡密验证等功能:
index.php
```
<?php
session_start();
if(!isset($_SESSION['username'])){
header("location:login.php");
}
?>
<html>
<head>
<title>卡密验证管理系统</title>
</head>
<body>
<h1>卡密验证管理系统</h1>
<p>欢迎 <?php echo $_SESSION['username']; ?> 登录!</p>
<a href="generate.php">生成卡密</a><br>
<a href="validate.php">验证卡密</a><br>
<a href="logout.php">退出登录</a>
</body>
</html>
```
login.php
```
<?php
session_start();
if(isset($_SESSION['username'])){
header("location:index.php");
}
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($username == 'admin' && $password == 'admin123'){
$_SESSION['username'] = $username;
header("location:index.php");
}
else{
$error = "用户名或密码错误!";
}
}
?>
<html>
<head>
<title>登录</title>
</head>
<body>
<h1>卡密验证管理系统</h1>
<?php if(isset($error)){ ?>
<p style="color:red;"><?php echo $error; ?></p>
<?php } ?>
<form method="post">
<label>用户名:</label><input type="text" name="username"><br>
<label>密码:</label><input type="password" name="password"><br>
<input type="submit" name="submit" value="登录">
</form>
</body>
</html>
```
logout.php
```
<?php
session_start();
session_destroy();
header("location:login.php");
?>
```
generate.php
```
<?php
session_start();
if(!isset($_SESSION['username'])){
header("location:login.php");
}
if(isset($_POST['submit'])){
$count = $_POST['count'];
$length = $_POST['length'];
$card_array = array();
for($i = 0; $i < $count; $i++){
$card = '';
for($j = 0; $j < $length; $j++){
$card .= rand(0, 9);
}
$card_array[] = $card;
}
$filename = 'cards.txt';
$handle = fopen($filename, 'a');
foreach($card_array as $card){
fwrite($handle, $card . "\n");
}
fclose($handle);
$message = "卡密生成成功!共生成 " . $count . " 个卡密。";
}
?>
<html>
<head>
<title>生成卡密</title>
</head>
<body>
<h1>卡密验证管理系统</h1>
<a href="index.php">返回首页</a><br><br>
<?php if(isset($message)){ ?>
<p style="color:green;"><?php echo $message; ?></p>
<?php } ?>
<form method="post">
<label>生成数量:</label><input type="text" name="count"><br>
<label>卡密长度:</label><input type="text" name="length"><br>
<input type="submit" name="submit" value="生成">
</form>
</body>
</html>
```
validate.php
```
<?php
session_start();
if(!isset($_SESSION['username'])){
header("location:login.php");
}
if(isset($_POST['submit'])){
$card = $_POST['card'];
$filename = 'cards.txt';
$handle = fopen($filename, 'r');
$card_found = false;
while(!feof($handle)){
$line = trim(fgets($handle));
if($line == $card){
$card_found = true;
break;
}
}
fclose($handle);
if($card_found){
$message = "卡密验证成功!";
}
else{
$error = "卡密无效或已被使用!";
}
}
?>
<html>
<head>
<title>验证卡密</title>
</head>
<body>
<h1>卡密验证管理系统</h1>
<a href="index.php">返回首页</a><br><br>
<?php if(isset($message)){ ?>
<p style="color:green;"><?php echo $message; ?></p>
<?php } ?>
<?php if(isset($error)){ ?>
<p style="color:red;"><?php echo $error; ?></p>
<?php } ?>
<form method="post">
<label>卡密:</label><input type="text" name="card"><br>
<input type="submit" name="submit" value="验证">
</form>
</body>
</html>
```
以上代码仅供参考,实际使用中需要根据具体需求进行修改和完善。
阅读全文