PHP développe un code d'implémentation de connexion complet pour un système simple de prêt de livres
Vous devez introduire le fichier de base de données config.php et le fichier public head.php
<?php include("head.php");?>
<?php include("config.php");?>Ce qui suit est le code complet de la page de connexion, le nom du fichier est landing.php.
<?php
include("config.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简单图书借阅系统登录</title>
<style>
body,td,th {font-family: 微软雅黑;font-size: 9px;color: #222;}
body {background-color: #FFFFFF;line-height:20px;}
a:link {color: #222;text-decoration: none;}
a:visited {text-decoration: none;color: #222;}
a:hover {text-decoration: underline;color: #FF0000;}
a:active {text-decoration: none;color: #999999;}
</style>
</head>
<?php
//初始化session
if(isset($_GET['tj']) == 'out'){
session_destroy();
echo "<script language=javascript>alert('退出成功!');window.location='landing.php'</script>";
}
if(isset($_POST['submit'])){
// 如果已经登录过,直接退出
if(isset($_SESSION['id'])) {
//重定向到管理留言
echo "<script language=javascript>alert('您已登陆');window.location='index.php'</script>";
// 登录过的话,立即结束
exit;
}
// 获得参数
$nickname=$_POST['username'];
$password=$_POST['password'];
//$password=md5($password);
// 检查帐号和密码是否正确,
$sql="select * from user where name='$nickname' and password='$password'";
$re = mysqli_query($link,$sql);
$result=mysqli_fetch_array($re);
// 如果用户登录正确
if(!empty($result)) {
//注册session变量,保存当前会话用户的昵称
$_SESSION['id']=$result['id'];
// 登录成功重定向到管理页面
echo "<script language=javascript>alert('登陆成功');window.location='index.php'</script>";
}
else {
// 管理员登录失败
echo "<script language=javascript>alert('密码不正确');window.location='landing.php'</script>";
}
}
?>
<body>
<?php include("head.php");?>
<form name="myform" method="post" onSubmit="return CheckPost()" action="" style="margin-bottom:5px;">
<table width="782" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height="30" colspan="2" bgcolor="#FFFFFF">用户登录</td>
</tr>
<tr>
<td width="337" align="right" bgcolor="#FFFFFF">用户名:
</td>
<td width="422" bgcolor="#FFFFFF"><input type="text" name="username"></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">密 码:
</td>
<td bgcolor="#FFFFFF"><input type="password" name="password"></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><a href="reg.php">注册新用户</a>
</td>
<td bgcolor="#FFFFFF"><input type="submit" name="submit" value="登录"></td>
</tr>
</table>
</form>
</body>
</html>
nouveau fichier
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简单图书管理系统登录</title>
<style>
body,td,th {font-family: 微软雅黑;font-size: 9px;color: #222;}
body {background-color: #FFFFFF;line-height:20px;}
a:link {color: #222;text-decoration: none;}
a:visited {text-decoration: none;color: #222;}
a:hover {text-decoration: underline;color: #FF0000;}
a:active {text-decoration: none;color: #999999;}
</style>
</head>
<body>
<form name="myform" method="post" onSubmit="return CheckPost()" action="" style="margin-bottom:5px;">
<table width="" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height="" colspan="2" bgcolor="#FFFFFF">用户登录</td>
</tr>
<tr>
<td width="" align="right" bgcolor="#FFFFFF">用户名:
</td>
<td width="" bgcolor="#FFFFFF"><input type="text" name="username"></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">密 码:
</td>
<td bgcolor="#FFFFFF"><input type="password" name="password"></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><a href="reg.php">注册新用户</a>
</td>
<td bgcolor="#FFFFFF"><input type="submit" name="submit" value="登录"></td>
</tr>
</table>
</form>
</body>
</html>
Aperçu
Clear
- Recommandations de cours
- Téléchargement du didacticiel
Le didacticiel n'est pas disponible au téléchargement pour le moment. Le staff est actuellement en train de l'organiser. Veuillez prêter plus d'attention à ce cours à l'avenir ~
Les étudiants qui ont regardé ce cours apprennent également
Parlons brièvement de la création d'une entreprise en PHP
Introduction rapide au développement web front-end
Développement pratique à grande échelle par Tianlongbabu du cadre MVC version Mini imitant le site Web de l'encyclopédie des choses embarrassantes
Premiers pas avec le développement pratique PHP : création rapide de PHP [Small Business Forum]
Vérification de connexion et forum de discussion classique
Collecte de connaissances sur les réseaux informatiques
Démarrage rapide de la version complète de Node.JS
Le cours front-end qui vous comprend le mieux : HTML5/CSS3/ES6/NPM/Vue/...[Original]
Écrivez votre propre framework PHP MVC (40 chapitres en profondeur/gros détails/à lire absolument pour que les débutants progressent)
















