Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function setCookie(cname, sword,cvalue, scalue) {
  3.     var d = new Date();
  4.     d.setTime(d.getTime() + (300000*24*60*60*1000));
  5.     var expires = "expires=" + d.toGMTString();
  6.     document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  7.     document.cookie = sword + "=" + scalue + ";" + expires + ";path=/";
  8. }
  9.  
  10. function getCookie(cname) {
  11.     var name = cname + "=";
  12.     var decodedCookie = decodeURIComponent(document.cookie);
  13.     var ca = decodedCookie.split(';');
  14.     for(var i = 0; i < ca.length; i++) {
  15.         var c = ca[i];
  16.         while (c.charAt(0) == ' ') {
  17.             c = c.substring(1);
  18.         }
  19.         if (c.indexOf(name) == 0) {
  20.             return c.substring(name.length, c.length);
  21.         }
  22.     }
  23.     return "";
  24. }
  25.  
  26. function deleteCookie(){
  27.     document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
  28.     document.cookie = "password=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
  29. }
  30.  
  31.  
  32. function checkCookie() {
  33.  
  34.  
  35.     var user = getCookie("username");
  36.     if (user != "") {
  37.         return true;
  38.         //alert("Welcome again " + user);
  39.     }
  40.     else {
  41.         return false;
  42.         window.location.href = "../HouseRent/Login.html";
  43.     }
  44.  
  45.     /* else {
  46.        user= prompt("Please enter your name:","");
  47.        if (user != "" && user != null) {
  48.            setCookie("username", user, 30);
  49.        }
  50.     }
  51.     */
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement