以下是一个简单的PHP登录注册页面的示例代码:
注册页面(register.php):
<!DOCTYPE html>
<html>
<head>
<title>注册</title>
</head>
<body>
<h2>注册</h2>
<form method="post" action="register_process.php">
<label for="username">用户名:</label>
<input type="text" name="username" id="username" required><br><br>
<label for="password">密码:</label>
<input type="password" name="password" id="password" required><br><br>
<input type="submit" value="注册">
</form>
</body>
</html>
注册处理页面(register_process.php):
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];
// 在此处进行用户名和密码的验证逻辑
// 假设验证通过,将用户名和密码保存到数据库中
// 这里只是一个示例,实际情况中需要使用安全的密码哈希算法进行保存
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// 将用户名和哈希密码保存到数据库中的用户表
// 注册成功后跳转到登录页面
header("Location: login.php");
exit();
}
?>
登录页面(login.php):
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
</head>
<body>
<h2>登录</h2>
<form method="post" action="login_process.php">
<label for="username">用户名:</label>
<input type="text" name="username" id="username" required><br><br>
<label for="password">密码:</label>
<input type="password" name="password" id="password" required><br><br>
<input type="submit" value="登录">
</form>
</body>
</html>
登录处理页面(login_process.php):
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];
// 在此处进行用户名和密码的验证逻辑
// 假设验证通过,进行登录操作
// 跳转到登录成功后的页面
header("Location: home.php");
exit();
}
?>
请注意,以上代码只是一个简单的示例,实际开发中需要根据具体需求进行逻辑处理和安全性考虑。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站