批改状态:未批改
老师批语:
<?php
$pagetitle = '首页';
include ('fg/header.php');
echo '<h2>我是首页</h2>';
if ((isset($_COOKIE['user_id'])) && basename($_SERVER['PHP_SELF']) != 'logout.php') {
echo '<a href="logout.php">退出</a>';
} else {
echo '<a href="login.php">登录</a>';
}
include ('fg/footer.php');点击 "运行实例" 按钮查看在线实例
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require ('fg/function.php');
require ('fg/connect.php');
// echo $_POST['id'];
// echo $_POST['password'];
// exit();
list($check, $data) = check_login($dbc, $_POST['id'], $_POST['password']);
if ($check) {
setcookie('user_id', $data['id']);
setcookie('user_name', $data['name']);
redirect_user('loggedin.php');
} else {
$errors = $data;
}
mysqli_close($dbc);
}
include('login_login.php');
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/点击 "运行实例" 按钮查看在线实例
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require ('fg/function.php');
require ('fg/connect.php');
// echo $_POST['id'];
// echo $_POST['password'];
// exit();
list($check, $data) = check_login($dbc, $_POST['id'], $_POST['password']);
if ($check) {
setcookie('user_id', $data['id']);
setcookie('user_name', $data['name']);
redirect_user('loggedin.php');
} else {
$errors = $data;
}
mysqli_close($dbc);
}
include('login_login.php');
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/点击 "运行实例" 按钮查看在线实例
<?php
$pagetitle = '用户登录';
include ('fg/header.php');
if (isset($errors) && !empty($errors)) {
$errors_msg = '<p style="color:red">';
foreach ($errors as $msg) {
$errors_msg .= $msg . '<br>';
}
echo $errors_msg . '</p>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="login.php" method="post">
<p>
<label for="id">邮箱:</label>
<input type="text" name="id" id="id" value="">
</p>
<p>
<label for="password">密码:</label>
<input type="password" name="password" id="password" value="">
</p>
<p>
<button type="submit" name="submit" id="submit">登录</button>
</p>
</form>
<?php
include ('fg/footer.php');
?>
</body>
</html>点击 "运行实例" 按钮查看在线实例
<?php
//echo $_COOKIE['id'];exit();
if (!isset($_COOKIE['user_id'])) {
require ('fg/function.php');
//跳转到默认首页
redirect_user();
}
//如果已经登录
//设置页面标题
$page_title = '已经登录';
include ('fg/header.php');
//打印欢迎信息,并提供退出功能
echo <<< "WELCOME"
<h2 style="color:red">登陆成功</h2>
<p>欢迎您: {$_COOKIE['user_name']}</p>
<p><a href="logout.php">退出</a></p>
WELCOME;
//加载底部
include ('fg/footer.php');点击 "运行实例" 按钮查看在线实例
<?php
if (!isset($_COOKIE['user_id'])) {
require ('fg/function.php');
//跳转到默认首页
redirect_user();
} else { //删除cookies
setcookie('user_id', '', time()-3600);
setcookie('user_name','', time()-3600);
}
//设置页面标题
$page_title = '已经登录';
include ('fg/header.php');
//打印退出信息,并提供登录功能
echo <<< "WELCOME"
<h2 style="color:red">退出成功</h2>
<p><a href="login.php">登录</a></p>
WELCOME;
include ('fg/footer.php');点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号