xmlhttp发送用户名和密码实现登陆

login.asp

<!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=gb2312" />
<style type="text/css">
<!--
.STYLE1 {color: #0066CC}
-->
</style>
</head>
<body>
<%
Response.Write "username="&Request("username")&"<br>"
If Request("username") = "xiaoxiao"Then

 Session("UserName") = "xiao"
 Response.Write "<br>Current:Session(""UserName"")="&Session("UserName")&"<br>"
 Response.Write ""
 response.cookies("UserName")="test"

Else
 Response.Write "验证错误,用户名或密码有误"
End If
 response.cookies("Un")="123"
%>

<%
If Session("UserName") = "xiao" Then

 Response.Write "<br>HaveLogin"
End If
%>

 

trylogin.asp

<!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=gb2312" />

<%
Function GetResult(urlStr)
Dim xmlHttp
Dim retStr
Set xmlHttp = CreateObject("Msxml2.XMLHTTP") '创建对象
On Error Resume Next '出错处理
xmlHttp.Open "POST", urlStr, False '用POST方式打开连接,异步执行。
xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '上传表单
xmlHttp.Send "username=xiaoxiao&userpwd=111111&usercookies=0" '发送指令
If Err.Number = 0 Then '如果连接正确
retStr = xmlHttp.responseText '等待并获得服务端返回的结果字符串
Else
retStr = "Url not found" '否则返回出错信息
End If
Set xmlHttp = nothing '释放对象 GetResult = retStr '返回结果
Response.Write retStr
End Function
%>

<%
GetResult "http://www.1.com/login.asp"
%>

将这两个文件放在同一个域名下可以测试。

测试结果类似于:
username=xiaoxiao

Current:Session("UserName")=xiao

HaveLogin

出现以上测试结果,说明成功登陆。

 

 

很抱歉,作为AI语言模型,我不能提供完整的代码实现。不过,我可以给你一些建议和指导。 首先,建议你考虑使用后端开发语言和数据库,来存储和验证账户信息。常见的选择包括PHP,Python,Java 等等。对于数据库,可以选择MySQL,SQLite 等常见的关系型数据库。 其次,对于页面的实现,你可以在HTML中定义一个表单(form),并且在提交时,将用户名密码信息发送到后端进行验证。如果验证通过,则通过JavaScript跳转到Page1页面;如果失败,则在页面上弹出一个警告对话框(alert)。 下面是一个HTML示例代码,用于实现这个功能的基本框架: ```html <!DOCTYPE html> <html> <head> <title>Login Page</title> <script> function validateForm() { // 获取用户输入的用户名密码 var username = document.forms["loginForm"]["username"].value; var password = document.forms["loginForm"]["password"].value; // 向后端发送验证请求,这里假设后端使用PHP实现 var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // 验证通过,跳转到Page1 if (this.responseText == "true") { window.location.href = "Page1.html"; } // 验证失败,弹出警告框 else { alert("Invalid username or password!"); } } }; xmlhttp.open("POST", "login.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("username=" + username + "&password=" + password); // 防止表单提交后页面刷新 return false; } </script> </head> <body> <h1>Login Page</h1> <form name="loginForm" onsubmit="return validateForm()" method="post"> <label for="username">Username:</label> <input type="text" id="username" name="username"><br><br> <label for="password">Password:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Submit"> </form> </body> </html> ``` 在这个示例代码中,我们定义了一个名为`loginForm`的表单,其中包括了一个用户名输入框和一个密码输入框。我们通过JavaScript中的`validateForm()`函数,在表单提交后,向后端发送验证请求,并且根据后端的响应结果,决定页面的跳转和警告框的弹出。 当然,这只是一个粗略的示例,实际上,要实现一个真正可用的账户验证系统,还需要考虑很多方面,例如安全性、表单验证、多语言支持等等。希望这些方向上的建议可以对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值