SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member Mara's Avatar
    Join Date
    Mar 2001
    Location
    Seattle
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation cookies, user preferences

    I am working, for the first time, with cookies...
    I have been able to set a cookie to the user's name and prefered page to view...
    My question is how do I personalize the page (welcome YOUR NAME...) I will be sending them to based on thier Preferences?
    Right now, I am welcoming them on the page where they set theier preference and then opening the new page in a new window...I somehow need to get thier name on that new page...
    Thank You So Much,
    Mara

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just rewrite this script for you

    PHP Code:
    <script type="text/javascript">

      var 
    expDays 30;

      var 
    exp = new Date(); 
      
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

      function 
    nom()
      {
        var 
    nom GetCookie('name');
        if (
    nom == null)
        {
          
    nom prompt("What is your name?");
          
    SetCookie('color'nomexp);
        }
        return 
    nom;
      }

      function 
    set()
      {
        
    fname prompt("What is your name?");
        
    SetCookie ('name'fnameexp);
        return 
    'Your name is: ' fname;
      }

      function 
    getCookieVal (offset)
      {
        var 
    endstr document.cookie.indexOf (";"offset);
        if (
    endstr == -1endstr document.cookie.length; return unescape(document.cookie.substring(offsetendstr));
      }

      function 
    GetCookie (name)
      {
        var 
    arg name "=";  
        var 
    alen arg.length;  
        var 
    clen document.cookie.length;  
        var 
    0;  

        while (
    clen)
        {
          var 
    alen;    

          if (
    document.cookie.substring(ij) == arg) return getCookieVal (j);
          
    document.cookie.indexOf(" "i) + 1;    

          if (
    == 0) break;
        }  
        return 
    null;
      }

      function 
    SetCookie (namevalue)
      {
        var 
    argv SetCookie.arguments;  
        var 
    argc SetCookie.arguments.length;  
        var 
    expires = (argc 2) ? argv[2] : null;  
        var 
    path = (argc 3) ? argv[3] : null;  
        var 
    domain = (argc 4) ? argv[4] : null;  
        var 
    secure = (argc 5) ? argv[5] : false;  
        
    document.cookie name '=' escape (value) + ((expires == null) ? '' : ('; expires=' expires.toGMTString())) + ((path == null) ? '' : ('; path=' path)) +  ((domain == null) ? '' : ('; domain=' domain)) + ((secure == true) ? '; secure' '');
      }

      function 
    DeleteCookie (name)
      {
        var 
    exp = new Date();  
        
    exp.setTime (exp.getTime() - 1);  
        var 
    cval GetCookie (name);  
        
    document.cookie name "=" cval "; expires=" exp.toGMTString();
      }
    // End -->
    </script>


    <div style="background-color:gray;" onclick="this.innerHTML=set()">click here to change name: <script type="text/javascript">document.write(nom());</script></div> 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •