<%
'乘风多用户计数器 Sql版
'作者QQ：178575
'作者EMail：yliangcf@163.com
'作者网站：http://www.qqcf.com
'详细简介：http://www.qqcf.com/cfcount.htm
'上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
'因为这些内容可能时常更新，就没有放在程序里，请自己上网站上查看
'有完整版本的演示
%>
<%
If Action="userloginsave" Then'用户登录
 UserName=Trim(GoBack(ChkStr(Request("UserName"),1),"请输入用户名称"))
 Pwd=Trim(GoBack(ChkStr(Request("Pwd"),1),"请输入用户密码"))
 Cookies_Time=CLng(ChkStr(Request("Cookies_Time"),2))
 CheckCode=ChkStr(Trim(Request("CheckCode")),1)

  '接口为Mysql
 If RsSet("RegType")=4 And CheckCode="" Then CheckCode=Session("ValidCode")

 If Session("ValidCode")<>CheckCode Then Call AlertUrl("四位数字的验证码输入错误!","Index.asp")
 

  If RsSet("RegType")=1 Then
   Set Rs=Server.CreateObject("Adodb.RecordSet")
   Sql="Select * From CFCount_User Where UserName='"&UserName&"'"
   Rs.Open Sql,Conn,1,1
   If Rs.Eof And Rs.Bof Then Call AlertUrl("没有此注册用户!","Index.asp")
   If Rs("Pwd")<>Md5(Pwd,1) Then Call AlertUrl("密码错误!","Index.asp")

  ElseIf RsSet("RegType")=2 Then
   Connstr_Rec="DBQ="+server.mappath(RsSet("AccessPath"))+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
   Set conn_Rec= Server.CreateObject ("ADODB.Connection")
   Conn_Rec.Open Connstr_Rec
   If Err Then
    Err.Clear
    Set Conn = Nothing
    'Response.Write "数据库连接出错，请检查连接字串。"
    'Response.End
   End If
   If RsSet("PassWordType")=1 then
    Sql="Select Count(*) From "&RsSet("SaveRegTable")&" where "&RsSet("SaveRegUserName")&"='"&UserName&"' And "&RsSet("SaveRegPassword")&"='"&Pwd&"'"
   ElseIf  RsSet("PassWordType")=2 then
    Sql="Select Count(*) From "&RsSet("SaveRegTable")&" where "&RsSet("SaveRegUserName")&"='"&UserName&"' And "&RsSet("SaveRegPassword")&"='"&Md5(Pwd,1)&"'"
   ElseIf  RsSet("PassWordType")=3 then
    Sql="Select Count(*) From "&RsSet("SaveRegTable")&" where "&RsSet("SaveRegUserName")&"='"&UserName&"' And "&RsSet("SaveRegPassword")&"='"&Md5(Pwd,2)&"'"
   End If
   Set Rs=Conn_Rec.ExeCute(Sql)   
   If Rs(0)=0 Then Call AlertUrl("用户名或密码输入有误","Index.asp")
   InsertUser=1
  ElseIf RsSet("RegType")=3 Then
   Connstr_rec="DRIVER={SQL Server};SERVER="&RsSet("SqlIP")&","&RsSet("SqlPort")&";UID="&RsSet("SqlLinkName")&";PWD="&RsSet("SqlLinkPassword")&";DATABASE="&RsSet("SqlDbName")&""
   Set Conn_Rec= Server.CreateObject ("ADODB.Connection")
   Conn_Rec.Open Connstr_rec
   If Err Then
    Err.Clear
    Set Conn = Nothing
    'Response.Write "数据库连接出错，请检查连接字串。"
    'Response.End
   End If
   If RsSet("PassWordType")=1 then
    Sql="Select Count(*) From "&RsSet("SaveRegTable")&" where "&RsSet("SaveRegUserName")&"='"&UserName&"' And "&RsSet("SaveRegPassword")&"='"&Pwd&"'"
   ElseIf  RsSet("PassWordType")=2 then
    Sql="Select Count(*) From "&RsSet("SaveRegTable")&" where "&RsSet("SaveRegUserName")&"='"&UserName&"' And "&RsSet("SaveRegPassword")&"='"&Md5(Pwd,1)&"'"
   ElseIf  RsSet("PassWordType")=3 then
    Sql="Select Count(*) From "&RsSet("SaveRegTable")&" where "&RsSet("SaveRegUserName")&"='"&UserName&"' And "&RsSet("SaveRegPassword")&"='"&Md5(Pwd,2)&"'"
   End If
   Set Rs=Conn_Rec.ExeCute(Sql)   
   If Rs(0)=0 Then Call AlertUrl("用户名或密码输入有误","Index.asp")
   InsertUser=1
  ElseIf RsSet("RegType")=4 Then
   InsertUser=1
  End If
  
  If InsertUser=1 Then
   If RsSet("RegAdminCheck") = -1 Then
    UserState = 0
   ElseIf RsSet("RegAdminCheck") = 0 Then
    UserState = -1
   End If

   If RsSet("UserUpload") = -1 Then
    UploadState = -1
   ElseIf RsSet("UserUpload") = 0 Then
    UploadState = 0
   End If

   EndDate=DateAdd("d", RsSet("UserUseDay"), Date())

    Set Rs= Server.CreateObject("ADODB.Recordset")
    Sql="Select Count(ID) From CFCount_User Where UserName='"&UserName&"'"
    Rs.Open Sql,Conn,3,2
	IF Rs(0)=0 Then
      Sql="Insert Into CFCount_User (UserName,UserState,EndDate,UploadState) Values ('"&UserName&"',"&UserState&",'"&EndDate&"',"&UploadState&")"	
	  Conn.Execute Sql'不存在此用户名插入这个用户的记录	  
	End If
	
  End If
 
 CFCountUserCookie=Md5(1&UserName&Pwd&SysCode,1)

 If Cookies_Time>0 Then
  Response.Cookies("CFCountUserCookie")=CFCountUserCookie
  Response.Cookies("CFCountUserCookie").expires=Dateadd("n",Cookies_Time,Now())
 End If

 Response.Cookies("CFCountGGCookie")="yes"
 Response.Cookies("CFCountGGCookie").expires=Dateadd("d",365,Now())

  If RsSet("RegType")=4 Then'为Myssql接口时,username,pwd参数名必须小写
   Response.Redirect "cf_phplogin.php?username="&UserName&"&pwd="&Pwd&"&cookies_time="&Cookies_Time
   Response.End
  Else
   Session("CFCountUser")=UserName

   Sql="Update CFCount_User Set LoginTotal=LoginTotal+1,LastLoginTime=getdate(),UserCode='"&CFCountUserCookie&"' Where UserName='"&UserName&"'"
   Conn.ExeCute Sql

   Response.Redirect "User_Manage.asp"
  End If
  
End If



If Action="userchecksave" Then'用户注册检查

 Response.Charset= "gb2312"

 UserName=ChkStr(Request("UserName"),1)
 If UserName="" Then
  Response.Write "请输入要检测的用户名"
  Response.End
 End if

 Set Rs= Server.CreateObject("ADODB.Recordset")
 Sql="Select Count(*) From CFCount_User Where UserName='"&UserName&"'"
 Rs.Open Sql,Conn,1,1
 If Rs(0)=0 Then
  Response.Write "恭喜，此用户还没有被注册!"
 Else
  Response.Write "对不起，此用户名已经被别人注册了!"
 End if  

 Response.End
End if

If Request("Action")="userregsave" Then'用户注册保存

UserName=Chkstr(Request.QueryString("UserName"),1)
TjType=Chkstr(Request.QueryString("TjType"),2)
UserCode=Chkstr(Request.QueryString("UserCode"),1)

Sql = "Select Count(*) From CFCount_User Where UserName='" & UserName & "' And UserCode='" & UserCode &"'"
Set Rs=Conn.Execute(Sql)
If Rs(0)>0 Then
 Session("CFCountUser")=UserName
   
 Response.Cookies("CFCountUserCookie")=UserCode
 Response.Cookies("CFCountUserCookie").expires=Dateadd("n",60,Now())

 Response.Cookies("CFCountGGCookie")="yes"
 Response.Cookies("CFCountGGCookie").expires=Dateadd("d",365,Now())
 
 If TjType=1 Then
  Response.Write "<script>location.href='User_Manage.asp?Action=webcodeget';</script>"
 Else
  Response.Write "<script>location.href='User_Manage.asp?Action=shopcodeget';</script>"
 End If
End If

End If




IF Action="adminloginsave" Then'管理员登录

Admin=GoBack(ChkStr(Request("Admin"),1),"请输入管理员名称")
Pwd=GoBack(ChkStr(Request("Pwd"),1),"请输入管理员密码")
Cookies_Time=CLng(ChkStr(Request("Cookies_Time"),2))
CheckCode=ChkStr(Trim(Request("CheckCode")),1)

If Session("ValidCode")<>CheckCode Then Call AlertRef("四位数字的验证码输入错误!")

Set Rs = Server.CreateObject("ADODB.Recordset")
Sql="Select * From CFCount_Admin where Admin='"&Admin&"'"
rs.open sql,conn,1,1

IF Rs.eof and Rs.bof Then Call AlertRef("没有此管理员名称!")
IF Rs("Pwd")<>Md5(Pwd,1) Then Call AlertRef("密码错误!")

Session("CFCountAdmin")="ok"

 CFCountAdminCookie=Md5(0&Admin&Pwd&SysCode,1)

 If Cookies_Time>0 Then
  Response.Cookies("CFCountAdminCooKie")=CFCountAdminCooKie
  Response.Cookies("CFCountAdminCooKie").expires=Dateadd("n",Cookies_Time,Now())
 End If

If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Then
 Ip = ChkStr(Request.ServerVariables("REMOTE_ADDR"),1)
Else
 Ip = ChkStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1)
End If
 
 Sql="Update CFCount_Admin Set Ip='"&Ip&"',LoginTotal=LoginTotal+1,LastLoginTime=getdate(),AdminCode='"&CFCountAdminCookie&"'"
 Conn.ExeCute Sql

 Response.Redirect "AdminUser_Manage.asp"
End If


'--独立查看用户登录
If Action="viewuserlogin" Then
 UserName=Trim(GoBack(ChkStr(Request("UserName"),1),"请输入用户名称"))
 Pwd_View=Trim(GoBack(ChkStr(Request("Pwd_View"),1),"请输入独立查看密码"))

 Set Rs=Server.CreateObject("Adodb.RecordSet")
 Sql="Select * From CFCount_User Where UserName='"&UserName&"'"
 Rs.Open Sql,Conn,1,1

 If Rs.Eof And Rs.Bof Then Call AlertBack("没有此注册用户!",1)

 If Rs("Pwd_View")<>Md5(Pwd_View,1) Then Call AlertBack("独立查看密码错误!",1)
 
 Session("CFCountUser_View")=UserName
 Response.Redirect "User_Manage.asp"
End If
%>