此文章仅做简单介绍,PHP密码登录系统的源码
一共需要三个源码,易捷博客把源码发放在文章中。
首先来看演示地址:
https://www.vxia.net/demo/phplogin/
三个源码分别为:login.php check.php index.php
login.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <br> <br> <center>易捷博客网 www.vxia.net </center> <table width="600" border="0" align="center" style="font-family:Verdana,宋体;font-size: 12px;"> <form action="check.php" method="post" onSubmit="return chkinput(this)"> <tr> <td width="160" height="25" align="right"> </td> <td width="400"><span class="STYLE1"></span></td> </tr> <tr> <td height="25" align="right">用户名 User Name:</td> <td> <input type="text" name="name" size="40" maxlength="80" value="" class="inputcss" /> <span class="STYLE1"> </span></td> </tr> <tr> <td height="25" align="right">密 码 Password: </td> <td> <span class="STYLE1"> <input type="text" name="password" size="40" maxlength="80" value="" class="inputcss" /> </span></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="提交" class="buttoncss" /> <input type="reset" value="重置" class="buttoncss"></td> </tr> </form> </table> </body> </html>
check.php:
在源码中设置用户名和密码
$_SESSION['name'] = "ycyjkj";
$_SESSION['password'] = "123456";
易捷博客设置的用户名是 ycyjkj 密码为 123456
<?php // session开始 session_start(); $name = $_POST['name']; $password = $_POST['password']; $_SESSION['name'] = "ycyjkj"; $_SESSION['password'] = "123456"; if ($password != $_SESSION['password'] && $name != $_SESSION['name']){ echo "密码错误!"; echo "<script>alert('密码错误'); history.go(-1);</script>"; } else if ($password == $_SESSION['password'] && $name == $_SESSION['name']){ $page="MessageBoardManager.php"; echo "<script>window.location = \"".$page."\";</script>"; } ?>
最后,找到你的源码中的首页,一般为 index.php,在此文件中添加以下代码:
在这里要注意:
if ("123456" != $_SESSION['password'] && "ycyjkj" != $_SESSION['name']){
123456 和 ycyjkj 要改成自己的账号密码
<?php // session开始 session_start(); if ("123456" != $_SESSION['password'] && "ycyjkj" != $_SESSION['name']){ $page="login.php"; echo "<script>window.location = \"".$page."\";</script>"; } ?>
演示地址:https://www.vxia.net/demo/phplogin/