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

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值