home *** CD-ROM | disk | FTP | other *** search
/ Magazyn WWW 1999 July / www_07_1999.iso / prez / amiga / KidHTML1_25.lha / KidHTML1.25 / Script / cookiepass.js < prev    next >
Text File  |  1998-08-25  |  3KB  |  113 lines

  1. <!-- TWO STEPS TO INSTALL COOKIE PASSWORD PROTECTION:
  2.  
  3.    1.  Put the designated coding into the HEAD of your login document
  4.    2.  Paste the final coding into the BODY of your login document  -->
  5.  
  6. <!-- STEP ONE: Copy this code into the HEAD of your login document  -->
  7.  
  8. <HEAD>
  9.  
  10. <SCRIPT LANGUAGE="JavaScript">
  11.  
  12. <!-- This script and many more are available online from -->
  13. <!-- The JavaScript Source!! http://javascriptsource.com -->
  14.  
  15. <!-- Begin
  16. function getCookieVal (offset) {
  17. var endstr = document.cookie.indexOf (";", offset);
  18. if (endstr == -1)
  19. endstr = document.cookie.length;
  20. return unescape(document.cookie.substring(offset, endstr));
  21. }
  22. function GetCookie (name)  {
  23. var arg = name + "=";
  24. var alen = arg.length;
  25. var clen = document.cookie.length;
  26. var i = 0;
  27. while (i < clen)  {
  28. var j = i + alen;
  29. if (document.cookie.substring(i, j) == arg)
  30. return getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;
  31. if (i == 0) break; 
  32. }
  33. return null;
  34. }
  35. function SetCookie (name, value)  {
  36. var argv = SetCookie.arguments;
  37. var argc = SetCookie.arguments.length;
  38. var expires = (argc > 2) ? argv[2] : null;
  39. var path = (argc > 3) ? argv[3] : null;
  40. var domain = (argc > 4) ? argv[4] : null;
  41. var secure = (argc > 5) ? argv[5] : false;
  42. document.cookie = name + "=" + escape (value) +
  43. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  44. ((path == null) ? "" : ("; path=" + path)) +
  45. ((domain == null) ? "" : ("; domain=" + domain)) +
  46. ((secure == true) ? "; secure" : "");
  47. }
  48. function DeleteCookie () { 
  49. var exp = new Date();
  50. exp.setTime (exp.getTime() - 1000000000);  // This cookie is history
  51. var cval = GetCookie ('FreeStuffL');
  52. document.cookie ='FreeStuffL' + "=" + cval + "; expires=" + exp.toGMTString();    
  53. }
  54. function cookieCreater () {
  55. if(GetCookie('FreeStuffL') == null) {
  56. var FreeStuffL_Name =  prompt ("What name do you want to go by?", "" );
  57. if (FreeStuffL_Name != null && FreeStuffL_Name != "") {
  58. var expdate = new Date (); 
  59. expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
  60. SetCookie('FreeStuffL', FreeStuffL_Name, expdate);  
  61. alert ("You now are logged in!  From now on, when you come to this page, you will be forwarded to the Password Protected Members-Only Area.  Please do not tell anyone your entry code.  At this new page, you will be shown a list of functions.  Have fun!");
  62. location.href = "cookie-in.html"
  63.    }
  64. }
  65. else {
  66. DeleteCookie ();
  67. cookieCreater ()
  68. }
  69. }
  70. if(GetCookie('FreeStuffL') != null) {
  71. location.href="cookie-in.html"
  72. }
  73. function check() {
  74. var tester = document.login.numOne.value + document.login.numTwo.value;
  75. if (tester == "") {
  76. alert ("I'm sorry, that code is not correct.");
  77. }
  78. else
  79. {
  80. if (tester == document.login.numThree.value) {
  81. alert ("That is correct!");
  82. cookieCreater ();
  83. }
  84. else {
  85. alert ("Nope!");
  86.       }
  87.    }
  88. }
  89. // End -->
  90. </SCRIPT>
  91.  
  92. <!-- STEP TWO: Copy this code into the BODY of your login document  -->
  93.  
  94. <BODY>
  95.  
  96. <center>
  97. <form name='login'>
  98. Enter your login code (FORMAT: login # one, login # two, login # three):
  99. <p><input TYPE='text' NAME='numOne' SIZE=15><br>
  100. <input TYPE='text' NAME='numTwo' SIZE=15 ><br>
  101. <input TYPE='text' NAME='numThree' SIZE=15 ><br>
  102. <input TYPE='button' VALUE='Login' ONCLICK='check()'>
  103. </form>
  104. </center>
  105. <font size=1 color=white>
  106. This page requires Javascript to run!  Please get Netscape 2.0 or greater!
  107. </font>
  108. <form name="login2">
  109. <input type=hidden name="go" value="cookie-in.html">
  110. </form>
  111.  
  112. <!-- Script Size:  3.44 KB  -->
  113.