Login Script Using Cookie
To prevent a user from directly accessing a page, login is required. This javascript is used to set the cookie for login and display visit count of the user.
Features
Used to set and get the cookie values. Simple and easy to use. Displays the visit count of the user.
Preview
Downloads
Javascript <!-- Script by hscripts.com --> <!-- More scripts @www.hscripts.com --> <script type="text/javascript"> var today = new Date(); var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) { endstr = document.cookie.length; } return unescape(document.cookie.substring(offset, endstr)); } function ctck() { var sds = document.getElementById("dum"); if(sds == null){ alert("You are using a free package.\n You are not allowed to remove the tag.\n"); } var sdss = document.getElementById("dumdiv"); if(sdss == null){ alert("You are using a free package.\n You are not allowed to remove the tag.\n"); } } document.onload="ctck()"; function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { return getCookieVal (j); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function DeleteCookie (name,path,domain) { if (GetCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } function SetCookie (name,value,expires,path,domain,secure) { document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } if (GetCookie('user_id') == null) { var getName = prompt('Hi... Welcome !!! First time We all have to through it. Please enter your name.', ''); var answer = confirm ('Hi... ' + getName + '. Do you want to remember your Name in future log in?') if (answer) { SetCookie('user_id', (getName != '' ? getName : 'Anonymous user'), expiry); SetCookie('hit_count', '1', expiry); } document.writeln('<H2>Welcome, ' + (getName != '' ? getName : 'Anonymous user') + '</H2>' + 'This is your first visit.'); } else { var getName = GetCookie('user_id'); var getHits = GetCookie('hit_count'); getHits = parseInt(getHits) + 1; document.writeln('<H2>Welcome Back, ' + getName + '</H2>' + 'You have visited ' + getHits + ' times.'); SetCookie('hit_count', '' + getHits + '', expiry); } </script> <div style="font-size: 10px;color: #dadada;" id="dumdiv"> <a href="https://www.hscripts.com" id="dum" style="text-decoration:none;color: dadada;">©h</a></div> <!-- Script by hscripts.com -->
Release Date - 11-02-2010 Get free version without ©copyright link for just $10/ -
For customization of this script or any script development, mail to support@hscripts.com
Usage
Copy and paste the javacript code into your HTML page and make use of this script.
This script is used to set and get the cookie values for your login.
It is also used to display your visit counts in a web page.
License
Related Scripts