asp登录认证,记录最后一次登录时间,写入数据库代码

2023-08-03

最近开发了一个船员招聘网的程序,但是由于部分功能需要配合ASP代码才能使用,所以就发现以前写的这个asp登录认证代码,今天就将他公布一下。

<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>.........</title>
<style type="text/css">
<!--
body,td,th {
font-size: 14px;
}
-->
</style>
<script language=javascript>
function CheckForm()
{
 if (document.Add.yonghu.value==""){
;
document.Add.yonghu.focus();
return false;
  }
  if (document.Add.mima.value==""){
;
document.Add.mima.focus();
return false;
  }
  if (document.Add.mima2.value==""){
;
document.Add.mima2.focus();
return false;
}
}
</script>
 
<%
if request("act")="login" Then
yonghu=Request.form("yonghu")
mima=Request.form("mima")
mima2=Request.form("mima2")
sql="select * from [sheng_admin] where yonghu='"&yonghu&"'"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,1
if rs.eof then
%>
<script language="javascript">
;
window.location="login.asp";
</script>
<%
else
if rs("mima")<>mima then
%>
<script language="javascript">
;
window.location="login.asp";
</script>
<%
else
if rs("mima2")<>mima2 then
%>
<script language="javascript">
;
window.location="login.asp";
</script>
<%
else
'写入COOKIE
session("admin")="sheng_admin"
session("yonghu")=rs("yonghu")
session("mima")=rs("mima")
session("shijian")=rs("shijian")
response.write "<script language="";window.location='sheng_center.asp';</script>"
rs.close
set rs=nothing
conn.close
set conn=nothing
 
'最后一次登录时间,写入数据库 https://www.ning8.cn
set rs1=server.createobject("adodb.recordset")
sql="select shijian from [sheng_admin] where yonghu='"&yonghu&"'"
rs1.open sql,conn,1,3
rs1("shijian")=now()
rs1.update
rs1.close
set rs1=nothing
 
end if
end if
end if
%>
<%end if%>
</head>
<body>
<p>&nbsp;</p>
<p align="center" style="color:#0066CC; font-size:18px; font-weight:bold;">&nbsp;</p>
<table width="273" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#EBEBEB">
<form name="Add" onSubmit="submit.disabled=1" action="login.asp?act=login" method="post">
  <tr>
    <td width="83" height="50" bgcolor="#FFFFFF" align="center">登录账号:</td>
    <td width="187" bgcolor="#FFFFFF"><input name="yonghu" type="text" id="yonghu" /></td>
  </tr>
  <tr>
    <td height="50" bgcolor="#FFFFFF" align="center">登录密码:</td>
    <td bgcolor="#FFFFFF"><input name="mima" type="text" id="mima" /></td>
  </tr>
  <tr>
    <td height="50" bgcolor="#FFFFFF" align="center">二次密码:</td>
    <td bgcolor="#FFFFFF"><input name="mima2" type="text" id="mima2" /></td>
  </tr>
  <tr>
    <td height="50" colspan="2" bgcolor="#FFFFFF" align="center"><input type="submit" name="Submit" value=" 登录认证 " onClick="return CheckForm();" /></td>
  </tr>
  </form>
</table>
</body>
</html>

asp登录认证,记录最后一次登录时间,写入数据库代码的相关教程结束。