title: how to force redirect to login page in javascript
body: <p>I am building a website where I want users to have to log in to be able to view a certin page (kn this case it is called gallery.php) I implemented some code I found on this site, which redirects the user back to the login page when they click on the gallery link in the menu. However when I log in, and get redirected to the gallery again, the website does not acknowledge that I have logged in and redirects me back to the login page again. I am aware that questions like this have been asked before, but any help would be appreciated. My code is bellow</p>
  
  <pre><code>//from login.html 
  &lt;!--//
  /*This Script allows people to enter by using a form that asks for a
  UserID and Password*/
  function pasuser(form) {
  if (form.id.value=="Admin") { 
  if (form.pass.value=="rycbar123") { 
  var sessionTimeout = 1; //hours
  var loginDuration = new Date();
  loginDuration.setTime(loginDuration.getTime()+(sessionTimeout*60*60*1000));
  document.cookie = "SistaDansenSession=Valid; "+loginDuration.toGMTString()+"; path=gallery.php";             
  location="gallery.php" 
  } else {
  alert("Invalid Password")
  }
  } else {  alert("Invalid UserID")
  }
  }
  
  //from gallery.php
  &lt;!--force login code--&gt;
  &lt;script type="text/javascript"&gt;
  if (document.cookie.indexOf("SistaDansenSession=Valid") == -1) {
  alert("You must be logged in to view this page")
  location.href = "login.html";
  }
  else {
  alert("login succesful")
  }  &lt;/script&gt;
  </code></pre>
  
  <p>Thanks so much</p>