检查是否支持!
<html><title>※ 网:域:科:技 - 无:限:商:机 ※ - Http://www.wykj.com</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>
<script Language="JavaScript">
<!-- hide script from non compliant broswers
// author: Roger W. Davis
//first, calculate an expiration for your temporary test cookie
var oneDay= 1*24*60*60*1000;
var expDate = new Date();
expDate.setTime (expDate.getTime() + oneDay);
var cookieExpires = expDate.toGMTString();
//just for completeness, get the browser information
document.write("Your browser is: <b>", navigator.appName,"</b><BR>");
document.write("Version: <b>",navigator.appVersion,"</b><BR>");
//set your temprorary cookie
document.cookie="verifyCookie=test; expires="+cookieExpires
//check to see if ANY cookies exist, including the one you just set
if (document.cookie.length>0)
document.write("Your browser supports cookies.<BR><BR>");
else {
document.write("Your browser doesn't support cookies, ")
document.write("or they're currently disabled.<BR><BR>");
document.write(document.cookie.substring(0,document.cookie.length)+"<BR><BR>");
}
//now be a good Netizen and clear out the unwanted stuff
document.cookie="verifyCookie=CLEAR; expires=Sun, 09-Nov-97 01:00:00 GMT";
//-->
</script>
<body>
<p>判断你的浏览器是否支持cookies</p>
<p>源代码:</p>
<p><br>
&lt;script Language="JavaScript"><br>
&lt;!-- hide script from non compliant broswers<br>
// author: Roger W. Davis<br>
<br>
//first, calculate an expiration for your temporary test cookie<br>
var oneDay= 1*24*60*60*1000;<br>
var expDate = new Date();<br>
expDate.setTime (expDate.getTime() + oneDay);<br>
var cookieExpires = expDate.toGMTString();<br>
//just for completeness, get the browser information<br>
document.write("Your browser is: &lt;b>", navigator.appName,"&lt;/b>&lt;BR>");<br>
document.write("Version: &lt;b>",navigator.appVersion,"&lt;/b>&lt;BR>");<br>
//set your temprorary cookie<br>
document.cookie="verifyCookie=test; expires="+cookieExpires<br>
//check to see if ANY cookies exist, including the one you just set<br>
if (document.cookie.length>0)<br>
document.write("Your browser supports cookies.&lt;BR>&lt;BR>");<br>
else {<br>
document.write("Your browser doesn't support cookies, ")<br>
document.write("or they're currently disabled.&lt;BR>&lt;BR>");<br>
document.write(document.cookie.substring(0,document.cookie.length)+"&lt;BR>&lt;BR>");<br>
}<br>
//now be a good Netizen and clear out the unwanted stuff<br>
document.cookie="verifyCookie=CLEAR; expires=Sun, 09-Nov-97 01:00:00 GMT";<br>
//--><br>
&lt;/script><br>
<br>
</p>
</body>
</html>
读写:
<html><title>※ 网:域:科:技 - 无:限:商:机 ※ - Http://www.wykj.com</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>
<script language="JavaScript1.2">
<!--
/*
This header must remain in place
Applies to Security aspect of script only
Title: Password Protection
http://www.plebius.org/javascripts/
Copyright 1999 All Rights Reserved.
http://www.plebius.org/copy.shtml
Owner: Plebius Industries
http://www.plebius.org
Author: Martin Kretzmann
scripts@plebius.org
License: GNU General Public License
http://www.plebius.org/scripts/license.html
*/
var GrantedURL = 'http://accept.html';
var DeniedURL = 'http://dontaccept.html';
var jim;
var gotoit;
suzy="0"
var capable;
var name = navigator.appName.toLowerCase();
var vers = parseFloat(navigator.appVersion);
if ((name.indexOf("netscape") >= 0 && vers >= 4) || (name.indexOf("microsoft") >= 0 && vers >= 4))
capable = true;
else
capable = false;
// Constants.
var FLDSEP; // Special characters used as separators in cookie data string.
var IDXSEP;
if (capable) {
FLDSEP = String.fromCharCode(1);
IDXSEP = String.fromCharCode(2);
}
//----------------------------------------------------------------------------
// Stores data currently entered on a form as cookies. Always returns true.
//
// name - The form name.
// months - Number of months to keep the cookies.
// exclude - A comma-delimited list of field names that should not be
// stored. Use to exclude sensitive data such as password,
// credit card numbers, etc.
//----------------------------------------------------------------------------
function storeData(name, months, exclude) {
var f;
var expdate;
var list, include;
var i;
var fld;
var data;
if ((document.myForm.pass.value==document.myForm.pass1.value)&&(document.jim.hiduser.value=="")&&(document.myForm.pass.value!="")){
name="jim";
document.jim.hidpass.value=document.myForm.pass.value;
document.jim.hiduser.value=document.myForm.user.value;
document.jim.hidname.value=document.myForm.name.value;
document.jim.hidhint.value=document.myForm.hint.value;
if (!capable)
return true;
// Get the named form, skip processing if not found.
if (!(f = document.forms[name]))
return true;
// Initialize the data field.
// Set the expiration date.
if (months == "")
months = 12;
expdate = new Date();
expdate.setMonth(expdate.getMonth() + months);
// Build a list of field names for exclusion.
list = new Array();
if (exclude != "") {
i = 0;
while ((i = exclude.indexOf(",")) >= 1) {
list[list.length] = exclude.substr(0, i);
exclude = exclude.substr(i + 1)
}
list[list.length] = exclude;
}
// Run through the fields and add field name/value pairs to the data string.
data = FLDSEP;
for (i = 0; i < f.length; i++) {
fld = f.elements;
// Is field in exclusion list?
include = true;
for (j = 0; j < list.length; j++)
if (fld.name == list[j])
include = false;
if (include) {
// Checkboxes and radio buttons.
if ((fld.type == "checkbox" || fld.type == "radio") && fld.checked)
data += setData(fld.name, fld.value);
// Selection lists (single).
if (fld.type == "select-one")
if (fld.selectedIndex >= 0)
data += setData(fld.name, fld.options[fld.selectedIndex].value);
// Selection lists (multiple). Add a unique name/value pair for each selected item.
if (fld.type == "select-multiple")
for (j = 0; j < fld.options.length; j++)
if (fld.options[j].selected)
data += setData(fld.name + IDXSEP + j, fld.options[j].value);
// Text fields.
if (fld.type == "hidden" || fld.type == "password" || fld.type == "text" || fld.type == "textarea")
data += setData(fld.name, fld.value);
}
}
// Set the cookie.
deleteCookie(name);
setCookie(name, data, expdate);
alert("user "+document.jim.hiduser.value+" has been added");
}
else if(document.myForm.pass.value==""||document.myForm.name.value==""||document.myForm.user.value==""||document.myForm.hint.value==""||document.myForm.pass1.value=="")
alert('fill in the form loser');
else alert("either your passwords don't match or you have registered with us before");
return true;
}
//----------------------------------------------------------------------------
// Retrieves data from the cookie and sets the values in the corresponding
// form fields. Returns true if data was found, false otherwise.
//
// name - The form name.
//----------------------------------------------------------------------------
function retrieveData(name) {
var f;
var i, j;
var fld;
var s;
var data;
if (!capable)
return false;
// Get the named form, return if not found.
if (!(f = document.forms[name]))
return false;
// Get the cookie for this form.
data = getCookie(name);
if (data == "")
return false;
// Run through the fields and retrieve the values.
for (i = 0; i < f.elements.length; i++) {
fld = f.elements;
// Checkboxes and radio buttons.
if ((fld.type == "checkbox" || fld.type == "radio") && (s = getData(fld.name, data)) != null && fld.value == s)
fld.checked = true;
// Selection lists (single).
if (fld.type == "select-one" && (s = getData(fld.name, data)) != null)
for (j = 0; j < fld.options.length; j++)
if (fld.options[j].value == s)
fld.options[j].selected = true;
// Selection lists (multiple).
if (fld.type == "select-multiple")
for (j = 0; j < fld.options.length; j++)
if ((s = getData(fld.name + IDXSEP + j, data)) != null && fld.options[j].value == s)
fld.options[j].selected = true;
// Text fields.
if ((fld.type == "hidden" || fld.type == "password" || fld.type == "text" || fld.type == "textarea") && (s = getData(fld.name, data)) != null)
fld.value = s;
}
return true;
}
/*****************************************************************************
* These functions set and retrieve the field name/value pairs stored in the *
* cookie. *
*****************************************************************************/
//----------------------------------------------------------------------------
// Given a field name and value, creates a name/value string that can be
// appended to the cookie data. A null string is returned if the given value
// is null.
//----------------------------------------------------------------------------
function setData(name, value) {
if (value != "")
return name + "=" + value + FLDSEP;
else
return "";
}
//----------------------------------------------------------------------------
// Given a field name, this function will extract the matching value found
// in the data string. Null is returned if no match is found.
//----------------------------------------------------------------------------
function getData(name, data) {
var i, j;
var s;
if (data == "")
return null;
s = FLDSEP + name + "=";
i = data.indexOf(s);
if (i >= 0) {
i += s.length;
j = data.indexOf(FLDSEP, i);
if (j >= 0)
return data.substr(i, j - i);
}
return null;
}
/*****************************************************************************
* These are the basic functions to set, get and delete a cookie. *
*****************************************************************************/
//----------------------------------------------------------------------------
// Set a cookie given a name, value and expiration date.
//----------------------------------------------------------------------------
function setCookie (name, value, expires) {
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}
//----------------------------------------------------------------------------
// Returns the value of the named cookie.
//----------------------------------------------------------------------------
function getCookie(name) {
var search;
search = name + "="
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length ;
end = document.cookie.indexOf(";", offset) ;
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(offset, end));
}
else
return "";
}
//----------------------------------------------------------------------------
// Delete the named cookie.
//----------------------------------------------------------------------------
function deleteCookie(name) {
var expdate = new Date();
expdate.setMonth(expdate.getMonth() - 1);
setCookie(name, "", expdate);
}
function checkpass(){
var bob;
if (document.jim.hiduser.value==document.jim.user.value)jim=true;
else jim=false;
if (document.jim.hidpass.value==document.jim.pass.value)bob=true;
else bob=false;
if ((jim==bob)&&(jim==true)){
alert("access granted");window.location=GrantedURL}
else {
suzy=suzy+1;
if (suzy>3){
alert("access denied, you will now be taken far away");
window.location=DeniedURL }
if (suzy<=3)
alert("access denied");
}
}
function getit(){
if (document.jim.hidhint.value==""){
alert("i/'m sorry "+document.jim.hidname.value+" but it appears you didn/'t answer the hint when you registered");}
else if (document.jim.hidhint.value==document.jim.hint.value){
alert("your password is "+document.jim.hidpass.value+".");}
else {alert("nope, that's not it")}
}
//-->
</script>
<!-- STEP TWO: Place the following in the BODY of your document -->
<BODY onLoad="retrieveData('jim')">
<table border=0 cellpadding=8 cellspacing=0 width=550>
<tr><td align=center colspan=2>
<hr noshade>
<p><b><font size="4">记录在这里</font></b></p>
<hr noshade>
</td></tr>
<tr valign=top>
<td bgcolor="#cccccc" width=100> </td>
<td width=450>
<!-- ANOTHER STEP: Set the form action to action="mailto:your email address" -->
<form name="myForm" method=post action="mailto:cn-zhang@21cn.com" onSubmit="storeData(this.name, 12,'user,pass,pass1,hint,name')">
<hr noshade>
<font size="3"><b>输入信息</b></font>
<p>
<table border=0 cellpadding=2 cellspacing=0>
<tr valign=bottom>
<td><b><font size="2">您的名字:</font></b></td>
<td colspan=3><input name="name" size=30 value=""></td>
</tr>
<tr valign=bottom>
<td><b><font size="2">用户名称:</font></b></td>
<td colspan=3><input name="user" size=30 value=""></td>
</tr>
<tr valign=bottom>
<td><b><font size="2">口令:</font></b></td>
<td colspan=3><input type="password" name="pass" size=30 value=""></td>
</tr>
<tr>
<td><b><font size="2">再输入一次:</font></b></td>
<td><input type="password" name="pass1" size=30 value=""></td>
</tr>
<tr valign=bottom>
<td><b><font size="2">口令提供答案:</font></b></td>
<td colspan=3><input name="hint" size=30 value="">
<input type="button" value="可以吗!" onClick="alert('your favorite sport is')"></td>
</tr>
</table>
<hr noshade>
<p align="center">
<input type="submit" value="同意">
<input type=reset value="清除">
</form>
<form name="jim" method=post>
<hr noshade>
<font size=3><b>登录</b></font>
<p>
<table border=0 cellpadding=2 cellspacing=0>
<tr valign=bottom>
<td><b><font size="2">用户名称:</font></b></td>
<td colspan=3><input name="user" size=30 value=""></td>
</tr>
<tr valign=bottom>
<td><b><font size=2>口令:</font></b></td>
<td colspan=3><input type="password" name="pass" size=30 value=""></td>
</tr>
<input type="hidden" name="hiduser" value="">
<input type="hidden" name="hidpass" value="">
<input type="hidden" name="hidname" value="">
<input type="hidden" name="hidhint" value="">
</table>
<hr noshade>
<p>
<input type="button" value="登录" onClick="checkpass()">
<tr valign=bottom>
<td><b><font size="2">忘记口令?</font></b>
<p><b><font size="2">答案:</font></b><font face="Courier New, Courier" size=2><b><input type="button" value="这里" onClick="alert('your favorite sport is')" </b></b></font></p>
</td>
<td colspan=3><input name="hint" size=30 value=""><BR><input type="button" value="获得口令" onClick="getit()"></td>
</tr>
</form>
</table>
<p>利用cookies读写密码</p>
<p>建议您另存此页面,慢慢研究源代码!</p>
</body>
</html>