diff --git a/core/clean.php b/core/clean.php new file mode 100644 index 0000000..df3fda7 --- /dev/null +++ b/core/clean.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/core/config.php b/core/config.php new file mode 100644 index 0000000..9397d17 --- /dev/null +++ b/core/config.php @@ -0,0 +1,13 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + echo "Connection failed: " . $e->getMessage(); +} +?> diff --git a/core/router.php b/core/router.php new file mode 100644 index 0000000..4d6d493 --- /dev/null +++ b/core/router.php @@ -0,0 +1,7 @@ +prepare("SELECT username FROM users WHERE username = ?"); + $checkStmt->execute([$username]); + + if ($checkStmt->rowCount() > 0) { + $title = '用户名已存在'; + $right_word = '注册'; + $href_url = '/?page=account'; + include('includes/time.php'); + } else { + $stmt = $pdo->prepare("INSERT INTO users (username, password, contact) VALUES (?, ?, ?)"); + + if ($stmt->execute([$username, $password, $contact])) { + $title = '注册成功'; + $right_word = '登录'; + $href_url = '/?page=account'; + include('includes/time.php'); + } else { + $title = '注册失败'; + $right_word = '注册'; + $href_url = '/?page=account'; + include('includes/time.php'); + } + } + } + } +} + +// 登录 +if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['login_username'])) { + $login_username = trim($_POST['login_username']); + $login_password = $_POST['login_password']; + + // 检查登录用户名是否为空 + if (empty($login_username)) { + $title = '用户名不能为空'; + $right_word = '登录'; + $href_url = '/?page=account'; + include('includes/time.php'); + } else { + $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$login_username]); + $user = $stmt->fetch(); + + if ($user && password_verify($login_password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $title = '登录成功'; + $right_word = '首'; + $href_url = '/'; + include('includes/time.php'); + } else { + $title = '用户名或密码错误'; + $right_word = '登录'; + $href_url = '/?page=account'; + include('includes/time.php'); + } + } +} +?> \ No newline at end of file diff --git a/includes/load_comments.php b/includes/load_comments.php new file mode 100644 index 0000000..f686a31 --- /dev/null +++ b/includes/load_comments.php @@ -0,0 +1,12 @@ +prepare("SELECT comments.content, users.username FROM comments JOIN users ON comments.user_id = users.id WHERE love_wall_id = ? ORDER BY comments.created_at DESC"); + $stmt->execute([$love_wall_id]); + while ($row = $stmt->fetch()) { + echo "
{$row['username']}: {$row['content']}
"; + } +} +?> diff --git a/includes/load_love_wall.php b/includes/load_love_wall.php new file mode 100644 index 0000000..212357e --- /dev/null +++ b/includes/load_love_wall.php @@ -0,0 +1,8 @@ +query("SELECT love_wall.content, users.username FROM love_wall JOIN users ON love_wall.user_id = users.id ORDER BY love_wall.created_at DESC"); +while ($row = $stmt->fetch()) { + echo "
{$row['username']}: {$row['content']}
"; +} +?> diff --git a/includes/onesay.php b/includes/onesay.php new file mode 100644 index 0000000..7c98189 --- /dev/null +++ b/includes/onesay.php @@ -0,0 +1,34 @@ + "秦涛", + "天涯何处无芳草,何必要在身边找,本来数量就不多,质量还不咋地" => "秦涛", + "弱小和无知,不是生存的障碍,傲慢才是" => "《三体》", + "你的无畏来源于无知" => "《三体》", + "要想逃避现实,最好的方式就是深深介入现实之中" => "《三体》", + "我爱你,与你有何相干?毁灭你,又与你有何相干?" => "《三体》", + "宇宙很大,生活更大,也许以后还有缘相见" => "《三体》", + "大多数人到死都没有向尘世之外瞥一眼" => "《三体》", + "碑是那么小,与其说是为了纪念,更像是为了忘却" => "《三体》", + "人们习惯将凡事分出黑与白,但很遗憾,现实全是灰色的" => "《三体》", + "没有不散的宴席,一切都有个尽头" => "《三体》", + "编程本身虽然是一种智力活动,但是中国的现实却更像一种体力劳动" => "《未来世界的幸存者》", + "我们只是让某些局部变得更有秩序,把混乱转移到另一些领域。" => "《未来世界的幸存者》", + "苦难就是苦难,苦难不会带来成功" => "《活着》", + "我的职业建议是,任何工作要么让你学习(learn),要么让你赚钱(earn)。如果既学不到新东西,又赚不到钱,你就应该走了" => "Garry Tan", + "编程既不是短跑,也不是马拉松,而是日记。在日复一日的累积当中,完成你的事业" => "《四十年编程感想》" +]; + +$randomKey = array_rand($quotes); +$quote = $randomKey; +$author = $quotes[$randomKey]; + +// 创建一个数组来存储名言和作者信息 +$response = [ + 'quote' => $quote, + 'author' => $author +]; + +// 将数组转换为 JSON 格式并输出 +echo json_encode($response); \ No newline at end of file diff --git a/includes/public/home.php b/includes/public/home.php new file mode 100644 index 0000000..e69de29 diff --git a/includes/submit_comment.php b/includes/submit_comment.php new file mode 100644 index 0000000..081315a --- /dev/null +++ b/includes/submit_comment.php @@ -0,0 +1,17 @@ +prepare("INSERT INTO comments (user_id, content, love_wall_id) VALUES (?, ?, ?)"); + $stmt->execute([$user_id, $content, $love_wall_id]); + } elseif (isset($_POST['article_id'])) { + $article_id = intval($_POST['article_id']); + $stmt = $pdo->prepare("INSERT INTO comments (user_id, content, article_id) VALUES (?, ?, ?)"); + $stmt->execute([$user_id, $content, $article_id]); + } +} +?> \ No newline at end of file diff --git a/includes/submit_love.php b/includes/submit_love.php new file mode 100644 index 0000000..03bb1c7 --- /dev/null +++ b/includes/submit_love.php @@ -0,0 +1,19 @@ +prepare("INSERT INTO love_wall (user_id, content) VALUES (?, ?)"); + + // 执行SQL语句 + if ($stmt->execute([$user_id, $content])) { + echo "发表成功!"; + } else { + echo "发表失败!"; + } +} +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..e8ca6bb --- /dev/null +++ b/index.php @@ -0,0 +1,16 @@ +