HTML code:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>untitled document</title>
<body>
<form name= "Frm1" method= "post" onsubmit= "Logincheck ()" >
<p>username:<input type= "text" name= "UserName"/></p>
<p>password:<input type= "Password" name= "Password"/></p>
<p>
<input type= "Submit" value= "Login"/>
<input type= "reset" value= "reset"/>
</p>
</form>
</body>
JS Code:
Copy Code code as follows:
<script language= "JavaScript" type= "Text/javascript" >
function Setcookie (name, value, expires, path, domain, secure) {
var Curcookie = name + "=" + encodeURI (value)
+ ((expires)? "; expires=" + expires.togmtstring (): "")
+ (path)? ";p ath=" + Path: "")
+ (domain)? ";d omain=" + domain: "")
+ (Secure)? "; Secure": "");
Document.cookie = Curcookie;
}
function GetCookie (name) {
if (Document.cookie.length > 0) {
Start = document.cookie.indexOf (name + "=");
If (Start!=-1) {
Start = start + Name.length + 1;
End = Document.cookie.indexOf (";", start);
if (end = = 1) {
end = Document.cookie.length;
}
}
Return decodeURI (document.cookie.substring (start,end));
}
Return "";
}
function Logincheck () {
var name = Document.frm1.username.value;
var pass = Document.frm1.password.value;
if (name = = "ZGHLX" && pass = "123") {
var login = true;
var now = new Date ();
Now.setdate (now.getdate () + 30);
Setcookie ("Login", Login,now);
Window.location.href = "index.html";
}
}
function Userlogin () {
var login = GetCookie ("login");
if (login!= null && login!= "") {
Alert ("Welcome ...");
Window.location.href = "index.html";
}
}
Userlogin ();
</script>