General discussion

  • Creator
    Topic
  • #2074112

    Write a cookie and the points are yours

    by adwait gupte ·

    I need a javascript cookie script that will write a cookie with the contents of a form and then when the user tries to login the script would compare the user name and the username on the cookie. There is no password. Also it will login the user andkeep a log of which links he has clicked and then make those links unavailable. The script should also keep track of how many links the user has clicked and read it each time he logs in and when the number reaches 200 should show a alert message. The number of links the user has clicked should be in a variable so that they can be shown on a page.

You are posting a reply to: Write a cookie and the points are yours

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Comments

  • Author
    Replies
    • #3776486

      Write a cookie and the points are yours

      by jeremy ·

      In reply to Write a cookie and the points are yours

      I would do that using session variables. I would use VBScript – create a
      database, and populate it with variables such as username, links, etc. Use
      event handlers (ie when a user clicks on a link, have an ‘onClick’ event to
      write to the db). Then, when the user logs in, you can immediately compare
      his username (assuming you are using Windows NT) with that in the database,
      and immediately access all the other info. You can then use the variables in
      the database to control what the user sees.

    • #3777272

      Write a cookie and the points are yours

      by mightyduk ·

      In reply to Write a cookie and the points are yours

      put the javascript in a file called challenge.js in the same directory:
      function login(){
      checkCookie();
      if(document.login_form.user.value!=user){
      alert(“Login Failed!”);
      return;}

      for(var i=0;i=200){
      alert(“Congratulations you hit 200!”);}
      }

      function checkCookie(){
      if(document.cookie){
      eval(document.cookie);
      var linklist=links.split(“,”);
      for(var i=1;i

    • #3777271

      Write a cookie and the points are yours

      by mightyduk ·

      In reply to Write a cookie and the points are yours

      and finally:

      function linkto(target){
      if(linksbyname[target.href]){
      document.login_form.user.select();
      document.login_form.user.focus();
      return false;
      }
      else {
      linksbyname[target.href]=true;
      target.id=”done”;
      numlinks++; document.login_form.numlinks.value=numlinks;
      links+=”,”+target.href;
      document.cookie=”links='”+links+”‘”+expiry;
      document.cookie=”numlinks=”+numlinks+expiry
      return true;
      }
      }

      var numlinks=0;
      var links=””;
      var expiry=”;expires=Fri, 31-Dec-2099 12:00:00 GMT”;
      var user=””;
      var linksbyname=new Array();

      the cookie will expire at the end of the century, should be long enough? It runs with IE5, you might have to play with it a little for Netscape. Email me if you have questions

    • #3766876

      Write a cookie and the points are yours

      by adwait gupte ·

Viewing 2 reply threads