diff --git a/pmconfig.php b/pmconfig.php
new file mode 100644
index 0000000..250a51d
--- /dev/null
+++ b/pmconfig.php
@@ -0,0 +1,17 @@
+ 'localhost', // 数据库主机
+ 'db_user' => 'a1sax1m9i',
+ 'db_pass' => 'a1sax1m9i',
+ 'db_name' => 'a1sax1m9i',
+ 'oss_access_key' => 'LTAI5tDRQoVXAVA6VrYHRXR9',
+ 'oss_secret_key' => 'P8QITod5r465AwBoI11uiwVBCc9SHd',
+ 'oss_endpoint' => 'oss-cn-shenzhen.aliyuncs.com',
+ 'oss_bucket' => 'sunmusic'
+];
+?>
\ No newline at end of file
diff --git a/profile.php b/profile.php
new file mode 100644
index 0000000..b30d825
--- /dev/null
+++ b/profile.php
@@ -0,0 +1,466 @@
+登录");
+ }
+
+ // 获取用户ID
+ if (isset($_SESSION['user_id']) && is_numeric($_SESSION['user_id'])) {
+ $userId = (int)$_SESSION['user_id'];
+ } else {
+ throw new Exception("无法获取用户ID,请重新登录");
+ }
+
+ // 加载配置文件
+ $config = [];
+ $configFile = 'pmconfig.php';
+ if (file_exists($configFile)) {
+ $config = include $configFile;
+ if (!is_array($config)) {
+ throw new Exception("配置文件必须返回一个数组");
+ }
+ } else {
+ throw new Exception("配置文件 pmconfig.php 不存在");
+ }
+
+ // 检查OSS配置
+ $ossParams = ['oss_access_key', 'oss_secret_key', 'oss_endpoint', 'oss_bucket'];
+ $missingOssParams = [];
+ foreach ($ossParams as $param) {
+ if (!isset($config[$param]) || empty($config[$param])) {
+ $missingOssParams[] = $param;
+ }
+ }
+ $ossConfigured = empty($missingOssParams);
+
+ // 引入OSS SDK
+ if ($ossConfigured) {
+ $ossSdkPath = __DIR__ . '/oss-sdk/autoload.php';
+ if (file_exists($ossSdkPath) && is_readable($ossSdkPath)) {
+ require_once $ossSdkPath;
+ $ossLoaded = class_exists('OSS\OssClient') && class_exists('OSS\Core\OssException');
+ }
+ }
+
+ // 生成头像URL
+ if ($ossConfigured && $ossLoaded) {
+ $bucket = $config['oss_bucket'];
+ $endpoint = preg_replace('/^https?:\/\//', '', $config['oss_endpoint']);
+ $object = 'sunmusic/profile/' . $userId . '头像.png';
+ $avatarUrl = "https://{$bucket}.{$endpoint}/{$object}?t=" . time();
+ }
+
+ // 数据库连接和用户信息获取
+ $dbRequired = ['db_host', 'db_user', 'db_name'];
+ $dbMissing = [];
+ foreach ($dbRequired as $param) {
+ if (!isset($config[$param]) || empty($config[$param])) {
+ $dbMissing[] = $param;
+ }
+ }
+
+ if (empty($dbMissing)) {
+ $conn = new mysqli(
+ $config['db_host'],
+ $config['db_user'],
+ $config['db_pass'] ?? '',
+ $config['db_name']
+ );
+
+ if ($conn->connect_error) {
+ throw new Exception("数据库连接失败: " . $conn->connect_error);
+ }
+
+ $conn->set_charset("utf8mb4");
+
+ // 获取用户信息
+ $stmt = $conn->prepare("SELECT nickname, email FROM users WHERE id = ?");
+ $stmt->bind_param("i", $userId);
+ $stmt->execute();
+ $result = $stmt->get_result();
+
+ if ($userData = $result->fetch_assoc()) {
+ $currentNickname = $userData['nickname'] ?? '未设置';
+ $currentEmail = $userData['email'] ?? '未设置';
+ } else {
+ throw new Exception("未找到用户信息");
+ }
+
+ $stmt->close();
+
+ // 处理基础信息更新
+ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_basic'])) {
+ $newNickname = trim($_POST['nickname'] ?? '');
+ $newEmail = trim($_POST['email'] ?? '');
+
+ $updates = [];
+ $params = [];
+ $types = '';
+
+ if (!empty($newNickname) && $newNickname !== $currentNickname) {
+ if (strlen($newNickname) < 2 || strlen($newNickname) > 20) {
+ throw new Exception("用户名长度必须在2-20个字符之间");
+ }
+ $updates[] = "nickname = ?";
+ $params[] = $newNickname;
+ $types .= "s";
+ }
+
+ if (!empty($newEmail) && $newEmail !== $currentEmail) {
+ if (!filter_var($newEmail, FILTER_VALIDATE_EMAIL)) {
+ throw new Exception("请输入有效的邮箱地址");
+ }
+
+ // 检查邮箱是否已被使用
+ $checkStmt = $conn->prepare("SELECT id FROM users WHERE email = ? AND id != ?");
+ $checkStmt->bind_param("si", $newEmail, $userId);
+ $checkStmt->execute();
+ $checkResult = $checkStmt->get_result();
+
+ if ($checkResult->num_rows > 0) {
+ throw new Exception("该邮箱已被其他用户使用");
+ }
+
+ $checkStmt->close();
+
+ $updates[] = "email = ?";
+ $params[] = $newEmail;
+ $types .= "s";
+ }
+
+ if (!empty($updates)) {
+ $sql = "UPDATE users SET " . implode(", ", $updates) . " WHERE id = ?";
+ $types .= "i";
+ $params[] = $userId;
+
+ $stmt = $conn->prepare($sql);
+ $bindParams = array_merge([$types], $params);
+ $tmp = [];
+ foreach ($bindParams as $key => $value) {
+ $tmp[$key] = &$bindParams[$key];
+ }
+ call_user_func_array([$stmt, 'bind_param'], $tmp);
+ $stmt->execute();
+ $stmt->close();
+
+ $currentNickname = $newNickname;
+ $currentEmail = $newEmail;
+ $message = "信息更新成功";
+ $messageType = 'success';
+ } else {
+ $message = "没有需要更新的信息";
+ $messageType = 'success';
+ }
+ }
+
+ $conn->close();
+ } else {
+ throw new Exception("数据库配置不完整(缺少: " . implode(', ', $dbMissing) . ")");
+ }
+
+ // 处理头像上传
+ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['upload_avatar']) && $ossConfigured && $ossLoaded) {
+ if (!isset($_FILES['avatar'])) {
+ throw new Exception("未收到上传文件");
+ }
+
+ // 检查上传错误
+ switch ($_FILES['avatar']['error']) {
+ case UPLOAD_ERR_OK:
+ break;
+ case UPLOAD_ERR_NO_FILE:
+ throw new Exception("请选择要上传的图片");
+ case UPLOAD_ERR_INI_SIZE:
+ case UPLOAD_ERR_FORM_SIZE:
+ throw new Exception("文件过大,超过上传限制");
+ default:
+ throw new Exception("上传错误,代码: " . $_FILES['avatar']['error']);
+ }
+
+ $avatarFile = $_FILES['avatar'];
+
+ // 验证文件
+ if (!is_uploaded_file($avatarFile['tmp_name'])) {
+ throw new Exception("文件上传异常");
+ }
+
+ $fileInfo = getimagesize($avatarFile['tmp_name']);
+ if (!$fileInfo) {
+ throw new Exception("不是有效的图片文件");
+ }
+
+ $allowedMime = ['image/jpeg', 'image/png', 'image/gif'];
+ if (!in_array($fileInfo['mime'], $allowedMime)) {
+ throw new Exception("不支持的图片类型");
+ }
+
+ if ($avatarFile['size'] > 10 * 1024 * 1024) {
+ throw new Exception("文件过大,最大支持10MB");
+ }
+
+ // OSS上传
+ $object = 'sunmusic/profile/' . $userId . '头像.png';
+ try {
+ $ossClient = new OSS\OssClient(
+ $config['oss_access_key'],
+ $config['oss_secret_key'],
+ $config['oss_endpoint']
+ );
+
+ $options = [
+ OSS\OssClient::OSS_HEADERS => [
+ 'x-oss-object-acl' => 'public-read',
+ ],
+ ];
+
+ $ossClient->uploadFile(
+ $config['oss_bucket'],
+ $object,
+ $avatarFile['tmp_name'],
+ $options
+ );
+
+ $endpoint = preg_replace('/^https?:\/\//', '', $config['oss_endpoint']);
+ $avatarUrl = "https://{$config['oss_bucket']}.{$endpoint}/{$object}?t=" . time();
+ $message = "头像上传成功!";
+ $messageType = 'success';
+ } catch (OSS\Core\OssException $e) {
+ throw new Exception("OSS错误: " . $e->getMessage());
+ }
+ }
+} catch (Exception $e) {
+ $message = $e->getMessage();
+ $messageType = 'error';
+}
+
+// 检测设备类型
+$isMobile = preg_match('/(android|iphone|ipad|ipod|blackberry|windows phone)/i', $_SERVER['HTTP_USER_AGENT']);
+?>
+
+
+
+
+
+ 个人信息
+
+
+
+
+
+
个人信息管理
+
+
+
+
+
+
+
+
+
个人头像
+
; ?>)
+
+
+
+
+
+
+
+
+
+
diff --git a/register.php b/register.php
new file mode 100644
index 0000000..a115ef5
--- /dev/null
+++ b/register.php
@@ -0,0 +1,284 @@
+ 20) {
+ $error = "用户名长度必须在3-20个字符之间";
+ } elseif (empty($email)) {
+ $error = "邮箱不能为空";
+ } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
+ $error = "请输入有效的邮箱地址";
+ } elseif (empty($password)) {
+ $error = "密码不能为空";
+ } elseif (strlen($password) < 6) {
+ $error = "密码长度不能少于6个字符";
+ } elseif ($password !== $confirm_password) {
+ $error = "两次输入的密码不一致";
+ } else {
+ // 连接数据库
+ $conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);
+
+ // 检查数据库连接
+ if ($conn->connect_error) {
+ $error = "数据库连接失败: " . $conn->connect_error .
+ "
使用的连接信息:
" .
+ "服务器: " . htmlspecialchars($servername) . "
" .
+ "用户名: " . htmlspecialchars($dbusername) . "
" .
+ "数据库名: " . htmlspecialchars($dbname);
+ } else {
+ // 检查用户名或邮箱是否已存在
+ $sql = "SELECT id FROM users WHERE username = ? OR email = ?";
+ $stmt = $conn->prepare($sql);
+
+ if (!$stmt) {
+ $error = "准备查询语句失败: " . $conn->error;
+ } else {
+ $stmt->bind_param("ss", $username, $email);
+ $stmt->execute();
+ $stmt->store_result();
+
+ if ($stmt->num_rows > 0) {
+ $error = "用户名或邮箱已被注册";
+ $stmt->close();
+ } else {
+ $stmt->close();
+
+ // 密码加密
+ $hashed_password = password_hash($password, PASSWORD_DEFAULT);
+
+ // 插入新用户
+ $sql = "INSERT INTO users (username, email, password_hash, nickname, created_at)
+ VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)";
+ $stmt = $conn->prepare($sql);
+
+ if (!$stmt) {
+ $error = "准备插入语句失败: " . $conn->error;
+ } else {
+ $stmt->bind_param("ssss", $username, $email, $hashed_password, $nickname);
+
+ if ($stmt->execute()) {
+ $success = true;
+
+ // 注册成功后自动登录(可选)
+ $_SESSION['user_logged_in'] = true;
+ $_SESSION['user_id'] = $conn->insert_id;
+ $_SESSION['user_info'] = [
+ 'username' => $username,
+ 'email' => $email,
+ 'nickname' => $nickname
+ ];
+
+ // 延迟跳转,让用户看到成功信息
+ if ($_POST['auto_login'] ?? true) {
+ header('Refresh: 2; URL=index.php');
+ }
+ } else {
+ $error = "注册失败: " . $stmt->error;
+ }
+
+ $stmt->close();
+ }
+ }
+ }
+
+ $conn->close();
+ }
+ }
+}
+?>
+
+
+
+
+
+
+ 用户注册 - 音乐分享网站
+
+
+
+
+
+
+
+
用户注册
+
+
+
+
+
+
+
+
+
+ 注册成功!感谢您的加入
+ 2秒后将自动跳转到首页...
+
+
+
+
+
+
+
+
+
diff --git a/reset_password.php b/reset_password.php
new file mode 100644
index 0000000..73f815c
--- /dev/null
+++ b/reset_password.php
@@ -0,0 +1,273 @@
+query($sql)) {
+ return "创建密码重置表失败: " . $conn->error;
+ }
+ return true;
+}
+
+// 检查令牌是否存在
+if (!isset($_GET['token']) || empty($_GET['token'])) {
+ $message = "无效的重置链接";
+ $messageType = "error";
+} else {
+ $token = $_GET['token'];
+
+ // 连接数据库
+ $conn = new mysqli($servername, $username, $password, $dbname);
+
+ // 检查数据库连接
+ if ($conn->connect_error) {
+ $message = "数据库连接失败: " . $conn->connect_error;
+ $messageType = "error";
+ } else {
+ // 确保密码重置表存在
+ $tableCheck = ensurePasswordResetTableExists($conn);
+ if ($tableCheck !== true) {
+ $message = $tableCheck;
+ $messageType = "error";
+ } else {
+ // 检查令牌是否有效且未过期
+ $sql = "SELECT user_id FROM password_reset_tokens WHERE token = ? AND expiry > NOW()";
+ $stmt = $conn->prepare($sql);
+
+ if (!$stmt) {
+ $message = "准备查询语句失败: " . $conn->error;
+ $messageType = "error";
+ } else {
+ $stmt->bind_param("s", $token);
+ $stmt->execute();
+ $stmt->store_result();
+
+ if ($stmt->num_rows == 1) {
+ // 令牌有效
+ $stmt->bind_result($userId);
+ $stmt->fetch();
+ $tokenValid = true;
+ } else {
+ $message = "重置链接无效或已过期";
+ $messageType = "error";
+ }
+
+ $stmt->close();
+ }
+ }
+
+ $conn->close();
+ }
+}
+
+// 处理表单提交
+if ($_SERVER["REQUEST_METHOD"] == "POST" && $tokenValid && $userId !== null) {
+ // 获取表单数据并过滤
+ $newPassword = $_POST['new_password'] ?? '';
+ $confirmPassword = $_POST['confirm_password'] ?? '';
+
+ // 表单验证
+ if (empty($newPassword)) {
+ $message = "新密码不能为空";
+ $messageType = "error";
+ } elseif (strlen($newPassword) < 6) {
+ $message = "密码长度不能少于6个字符";
+ $messageType = "error";
+ } elseif ($newPassword !== $confirmPassword) {
+ $message = "两次输入的密码不一致";
+ $messageType = "error";
+ } else {
+ // 连接数据库
+ $conn = new mysqli($servername, $username, $password, $dbname);
+
+ // 检查数据库连接
+ if ($conn->connect_error) {
+ $message = "数据库连接失败: " . $conn->connect_error;
+ $messageType = "error";
+ } else {
+ // 哈希密码
+ $hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
+
+ // 更新用户密码
+ $sql = "UPDATE users SET password_hash = ? WHERE id = ?";
+ $stmt = $conn->prepare($sql);
+
+ if (!$stmt) {
+ $message = "准备更新语句失败: " . $conn->error;
+ $messageType = "error";
+ } else {
+ $stmt->bind_param("si", $hashedPassword, $userId);
+
+ if ($stmt->execute()) {
+ // 密码更新成功,删除令牌
+ $deleteStmt = $conn->prepare("DELETE FROM password_reset_tokens WHERE user_id = ?");
+ $deleteStmt->bind_param("i", $userId);
+ $deleteStmt->execute();
+ $deleteStmt->close();
+
+ $message = "密码已成功重置,请使用新密码登录";
+ $messageType = "success";
+ $tokenValid = false; // 防止再次提交
+ } else {
+ $message = "密码更新失败,请稍后再试";
+ $messageType = "error";
+ }
+
+ $stmt->close();
+ }
+
+ $conn->close();
+ }
+ }
+}
+?>
+
+
+
+
+
+
+ 重置密码 - 音乐分享网站
+
+
+
+
+
+
重置密码
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sou.php b/sou.php
new file mode 100644
index 0000000..308da0e
--- /dev/null
+++ b/sou.php
@@ -0,0 +1,667 @@
+ ['name' => '全部音乐', 'color' => '#b89e81', 'text_color' => '#5d4037'],
+ 'cantonese' => ['name' => '粤语歌曲', 'color' => '#c8e6c9', 'text_color' => '#2e7d32'],
+ 'mandarin' => ['name' => '国语歌曲', 'color' => '#fff3e0', 'text_color' => '#e65100'],
+ 'waiyu' => ['name' => '外语歌曲', 'color' => '#e3f2fd', 'text_color' => '#0d47a1'],
+ 'classic' => ['name' => '经典老歌', 'color' => '#efebe9', 'text_color' => '#3e2723'],
+ 'other' => ['name' => '其他音乐', 'color' => '#f3e5f5', 'text_color' => '#6a1b9a']
+];
+
+// 获取音乐列表数据
+$musicList = require_once __DIR__ . '/data/music.php';
+
+// 获取并清理搜索词
+$searchTerm = isset($_GET['s']) ? trim($_GET['s']) : '';
+
+// 搜索功能:匹配歌名或歌手(不区分大小写)
+$searchResults = [];
+if (!empty($searchTerm)) {
+ $lowerTerm = strtolower($searchTerm);
+ foreach ($musicList as $music) {
+ if (strpos(strtolower($music['title']), $lowerTerm) !== false ||
+ strpos(strtolower($music['artist']), $lowerTerm) !== false) {
+ $searchResults[] = $music;
+ }
+ }
+}
+
+// 获取当前页面URL
+function getCurrentPageURL() {
+ $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
+ $host = $_SERVER['HTTP_HOST'];
+ $script = $_SERVER['SCRIPT_NAME'];
+ return $protocol . $host . $script;
+}
+$currentPageUrl = getCurrentPageURL();
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
返回主页
+
音乐搜索
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
作者:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
未找到相关结果
+
没有找到与 "" 相关的音乐
+
请尝试其他关键词或浏览全部音乐
+
+
+
+
+
请输入搜索关键词
+
在上方搜索框中输入音乐名称或歌手名进行搜索
+
+
+
+
+
+
+
+
+ 链接已复制到剪贴板!
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file