php邮箱登录注册界面
时间: 2023-07-09 10:50:25 浏览: 54
以下是一个简单的 PHP 邮箱登录注册界面的代码示例:
index.php
```
<!DOCTYPE html>
<html>
<head>
<title>邮箱登录/注册</title>
</head>
<body>
<h2>邮箱登录</h2>
<form action="login.php" method="post">
<label for="email">邮箱:</label>
<input type="email" id="email" name="email" required>
<br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<br><br>
<input type="submit" value="登录">
</form>
<br>
<hr>
<h2>邮箱注册</h2>
<form action="register.php" method="post">
<label for="name">姓名:</label>
<input type="text" id="name" name="name" required>
<br><br>
<label for="email">邮箱:</label>
<input type="email" id="email" name="email" required>
<br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<br><br>
<input type="submit" value="注册">
</form>
</body>
</html>
```
login.php
```
<?php
session_start();
if (isset($_POST['email']) && isset($_POST['password'])) {
$email = $_POST['email'];
$password = $_POST['password'];
// 在这里验证用户输入的邮箱和密码是否正确
// 如果正确,将用户信息保存到 session 中
$_SESSION['name'] = 'John Doe';
$_SESSION['email'] = $email;
// 重定向到用户主页
header('Location: user.php');
exit();
}
?>
```
register.php
```
<?php
session_start();
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
// 在这里将用户信息保存到数据库中
// 这里只是一个示例,实际应用中应该使用加密算法对密码进行加密
$user = array(
'name' => $name,
'email' => $email,
'password' => $password
);
// 将用户信息保存到 session 中
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
// 重定向到用户主页
header('Location: user.php');
exit();
}
?>
```
user.php
```
<?php
session_start();
if (!isset($_SESSION['email'])) {
// 如果用户未登录,重定向到登录页面
header('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>用户主页</title>
</head>
<body>
<h2>欢迎回来,<?php echo $_SESSION['name']; ?>!</h2>
<p>您的邮箱是:<?php echo $_SESSION['email']; ?></p>
<a href="logout.php">退出登录</a>
</body>
</html>
```
logout.php
```
<?php
session_start();
session_destroy();
// 重定向到登录页面
header('Location: index.php');
exit();
?>
```
以上代码仅供参考,实际应用中需要根据具体需求进行修改和完善。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)