16-3 ���νd�ҡG���N�������K�X�{��

¥»¸`±N¨Ï¥Î¡u±K½X»{ÃÒ¡v¬°½d¨Ò¡A¨Ó»¡©ú¦p¦ó¾ã¦X client-side script ¤Î server-side script¡A¨Ó¹F¨ì¤è«Kªº±K½X»{ÃÒ¥\¯à¡C¥»½d¨Òªº¯SÂI¦p¤U¡G
  1. §¹¥þ¤£»Ý­n¥Î¨ì IIS ©Î¦øªA¾¹§@·~¨t²Î¥»¨­ªº»{ÃÒ¥\¯à¡A©Ò¥H¤£»ÝºÞ²zªÌ¡]Administrator¡^Åv­­¡A¤]¥i¨Ï¥Î¡C
  2. ¨Ï¥Î¤è«K¡A¥u»Ý¦b³Q±K½X«OÅ@ªººô­¶¾É¤J¡]Include¡^¤@­ÓÀÉ®×§Y¥i¡C
  3. ¨Ï¥Î session ÅܼơA¨C¦¸»{ÃÒ«á¡A¦³®Ä®É¶¡¬° 20 ¤ÀÄÁ¡C
¬°Â²¤Æ»¡©ú¡A§Ú­Ì¨Ï¥Î¡u¥Ø¼Ðºô­¶¡v¨Ó¥Nªí¡u³Q±K½X«OÅ@ªººô­¶¡v¡A¨Ã¨Ï¥Î¡u¨Ó·½ºô­¶¡v¨Ó¥Nªí¥]§t¡u¥Ø¼Ðºô­¶¡v³sµ²ªººô­¶¡C¤U¦Cºô­¶¡]password/source.asp¡^¬O¥»½d¨Òªº¶i¤JÂI¡G

Example¡]password/source.asp¡^¡G

¤W­z½d¨Òªº§¹¾ã­ì©lÀɮצp¤U¡G

­ì©lÀÉ¡]password/source.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=jscript%>
<%title="¸g¥Ñ Session ÅܼƫO¦s±K½X»{ÃÒ¡G Client ©M Server ªº¾ã¦X¹B¥Î"%>
<!--#include file="../head.inc"-->
<hr>

<p align=center>½ÐÂI¿ï¦¹<a href="target.asp">¯µ±Kºô­¶</a>¡I
<p align=center>¡]¥»­¶¬° "source.asp"¡^

<hr>
<!--#include file="../foot.inc"-->

¦b¤W­z½d¨Ò¤¤¡A¥u­n¨Ï¥ÎªÌÂI¿ï¡u¯µ±Kºô­¶¡v¡A´N·|¶}±Ò±K½X»{ÃÒµøµ¡¡A¦p¤U¡G

¦¹ºô­¶¤w¸g±N¥¿½Tªº±b¸¹©M±K½X¶ñ¦b¤å¦rÄæ¦ì¡A¦]¦¹¥u­nÂI¿ï¡u°e¥X¡v¡A¦¹»{ÃÒµøµ¡´N·|³QÃö±¼¡A¨Ã¦b­ìµøµ¡Åã¥Ü¡u¯µ±Kºô­¶¡v¡G

§Ú­Ì²{¬Ý¬Ý¦¹¡u¯µ±Kºô­¶¡vªº­ì©l½X¡G

­ì©lÀÉ¡]password/target.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=jscript%>
<!--#include file="auth.inc"-->
<%title = "¯µ±Kºô­¶" %>
<!--#include file="../head.inc"-->
<hr>

<p align=center>±z¤w¦¨¥\µn¤J¯µ±Kºô­¶¡I</h3>
<p align=center>¥»ºô­¶¬° "target.asp"¡A¬ÛÃö session ÅܼƦp¤U¡G
<br>Session("source") = <%=Session("source")%>
<br>Session("target") = <%=Session("target")%>

<p align=center>
<a href="delauth.asp">®ø°£»{ÃÒ¸ê°T</a><br>

<hr>
<!--#include file="../foot.inc"-->

¦¹­ì©l½X©M¤@¯ë ASP ºô­¶¨ÃµL¯S²§¤§³B¡A°ß¤@ªº®t§O¬O¦b­ì©lÀɮתº²Ä¤@¦C¡A¥]§t¤F¥t¤@­ÓÀÉ®× auth.inc ¨Ó­t³d»{ÃÒ¡A³o¬O¥»½d¨ÒªºÃöÁä©Ò¦b¡A¨ä¤º®e¦p¤U¡G

­ì©lÀÉ¡]password/auth.inc¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%
// ¥»­¶¤§¥ô°È¬°ÀËÅç»{ÃÒ¸ê°T¬O§_¦s¦b¡G
// 1. ­Y¦s¦b¡A«h¤£°µ¥ô¦ó¨Æ¡C
// 2. ­Y¤£¦s¦b¡A«h¸õ¥X»{ÃÒµøµ¡¡]auth.asp¡^¡A½Ð¨D¿é¤J±K½X¡A¨Ã¦b­ìµøµ¡¸ü¤J­ìºô­¶¡]source.asp¡^¡C

// ¥ô¦ó»Ý­n±K½X«OÅ@¤§ºô­¶¡A¥u»Ý­n include ¦¹ÀɮסA§Y¥i¹F¨ì«OÅ@¥\¯à¡C
%>

<script>
function getPassword() {	// Åã¥Ü»{ÃÒµøµ¡
	var toURL = "auth.asp";
	win1 = window.open(toURL, "getPassword", "height=300, width=500, alwaysRaised");
}
</script>

<% // ©w¸q¨ç¼Æ¡A½T»{»{ÃÒ¸ê°T¬O§_¦s¦b
function authentication(sessionVariable){
	// This file is usually loaded twice after the user has input the password correctly.
	// When it's loaded the second time, Request.ServerVariables("HTTP_REFERER") will be empty since the page is loaded via a JavaScript in the authentication window
	if ((Request.ServerVariables("HTTP_REFERER")+"")!="undefined")	// §ä¥X¨Ó·½ºô­¶
		Session("source") = (Request.ServerVariables("HTTP_REFERER")+"");
	Session("target") = Request.ServerVariables("URL")+"";	// ¥Ø¼Ðºô­¶
	if (Request.ServerVariables("QUERY_STRING")!="")
		Session("target") = Session("target") + "?" + Request.ServerVariables("QUERY_STRING");
	if (!sessionVariable){ %>
		<script>
		getPassword();		// Åã¥Ü»{ÃÒµøµ¡
		history.go(-1);		// ¸ü¤J¨Ó·½ºô­¶
		</script>
		<% Response.End()
	}
}

authentication(Session("ok")); %>

¦b¦¹­ì©lÀɤ¤¡A§Ú­Ì©w¸q¤F¨â­Ó¨ç¼Æ¡A¤À§O¦b¥Î¤áºÝ»P¦øªA¾¹ºÝ°õ¦æ¡A¸ê»¡©ú¦p¤U¡G

¦¹¥~¡A­Y»{ÃÒ¸ê°T¤£¦s¦b¡A§Ú­Ì¥²¶·¶}±Ò»{ÃÒµøµ¡¡A¤º®e¦p¤U¡G

­ì©lÀÉ¡]password/auth.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=jscript%>
<%title="±K½X»{ÃÒºô­¶"%>
<!--#include file="../head.inc"-->
<hr>
<%  
// ¦¹­¶¤§¥Øªº¬°¶i¦æ±K½X»{ÃÒ¡G
// 1. ­Y³q¹L¡A«h©ó­ìµøµ¡¶}±Ò³Q«OÅ@¤§ target.asp ºô­¶
// 2. ­Y¤£³q¹L¡A«h½Ð¨D­«·s¿é¤J±b¸¹¡B±K½X

login=Request("login")+"";
password=Request("password")+"";
if ((login=="jang") && (password=="jang")){
	Session("ok") = true; %>
	<script>
	window.opener.document.location="<%=Session("target")%>";	// ©ó­ìµøµ¡¶}±Ò target ºô­¶
	window.close();							// Ãö³¬±K½X»{ÃÒµøµ¡
	</script>
<% } else {
//	if ((Request.ServerVariables("HTTP_REFERER")+"")!="undefined")	// ¦¹ºô­¶°e¥X«á©I¥s¦Û¤v¡]­Y¥Ñ window.open() ©Ò¶}¡A¨S¦³ referer¡^
	if ((login!="undefined") && (password!="undefined"))		// ¦¹ºô­¶°e¥X«á©I¥s¦Û¤v
		Response.Write("<p align=center>¸ê®Æ¦³»~¡A½Ð­«¸Õ¡G<br>");
%>
	<form method=post>
	<table border=0 align=center>
	<tr><td align=right>±b¸¹¡G<td><input name="login" value="jang">
	<tr><td align=right>±K½X¡G<td><input type=password name="password" value="jang">
	<tr><td align=center colspan=2><input type=submit></a>
	</table>
	</form>
<%
}
%>
<hr>

¦¹ºô­¶¤§¥\¯à¥i¥H»¡©ú¦p¤U¡G

  1. ­Y¨Ï¥ÎªÌ¿é¤J¥¿½Tªº±b¸¹±K½X¡A«h³]©w Session("ok") ¬° true¡A¦P®É¦b­ìµøµ¡¶}±Ò¥Ø¼Ðºô­¶¡A¨ÃÃö³¬»{ÃÒµøµ¡¡C
  2. ­Y±b¸¹±K½X¤£¥¿½T¡A«h¦b»{ÃÒµøµ¡Åã¥Ü­ì¨Óªº»{ÃÒµe­±¡C
±ýÁA¸Ñ¦¹½d¨Ò¡A½ÐŪªÌª½±µ¶}±Ò¦¹½d¨Ò¡A¨Ã¨ì³BÂI¿ï¬Ý¬Ý¡A¥H¼ô±x¨ä¹B§@¡C¤W­z½d¨Òªº¬yµ{¡A¥i»¡©ú¦p¤U¡G

  1. ¨Ï¥ÎªÌ±q source.asp ¡]¨Ó·½ºô­¶¡^¤¤ÂI¿ï target.asp¡]¥Ø¼Ðºô­¶¡^¡C
  2. target.asp ·|Àˬd¬O§_¦³¤w¸g¹L¥¿½T»{ÃÒ¡]¥B®É¶¡¤£¶W¹L 20 ¤ÀÄÁ¡^¡A¦¹¸ê°T«O¯d¦b session("ok")¡C­Y¦¹ÅܼƬ° True¡A«hÅã¥Ü target.asp¡C
  3. ­Y session("ok") ¬° False¡A¥Nªí»Ý­n»{ÃÒ¡A¦¹®É«h¸õ¥X±K½X»{ÃÒºô­¶¡A¨Ã¦b­ìµøµ¡¸ü¤J source.asp¡C
  4. ¨Ï¥ÎªÌ¦b»{ÃÒµøµ¡¿é¤J»{ÃÒ¸ê°T¡A­Y¿ù»~¡A«O«ù»{ÃÒµøµ¡¶}±Ò¡A¨ÃÄ~Äò­n¨D»{ÃÒ¸ê°T¡C
  5. ­YÀò±o¥¿½T»{ÃÒ¸ê°T¡A«hÃö³¬»{ÃÒµøµ¡¡A³]©w session("ok") ¬° True¡A¨Ã¦b­ìµøµ¡¶}±Ò target.asp¡C
¤W­z»¡©ú¡A¥i¥Î¬yµ{¹ÏÅã¥Ü¦p¤U¡G

Example¡]password/password.ppt¡^¡G

¦b¦¹½d¨Ò¤¤¡AÁ`¦@²o¯A¨ì¤­­ÓÀɮסA¬°¤F¨ó§UŪªÌÁA¸Ñ¦¹½d¨Ò¡A§Ú­Ì±N¦¹¤­­ÓÀɮתº¥\¯à¤À§O»¡©ú¦p¤U¡G


JScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©ó¦øªA¾¹ºÝªº ASP Àô¹Ò