The automatic login cookie javascript

2010-04-18  来源:本站原创  分类:Web  人气:493 

Written CssRain: http://www.cssrain.cn

--- Marks <o:p> </ o: p>

Cookie site or forum Automatic logon cookie technology is used most difficult to do. Haha with me was not difficult to

<o:p> </ o: p>

1. We first look at the cookie to automatically log on principle. <o:p> </ o: p ><!---->

<!---->
When users log in, you can choose how long usually do not have to log on, here is the validity of cookie settings, and login cookie will be stored in local hard disk, of course, we do not have to care about the pull. Then when the user next logon, the system will first go to test whether the current user's cookie exists, it exists then jump to the appropriate page, if you do not exist, should be the login page. Principle is such a simple analysis. Simple bar.

<o:p> </ o: p>

Two. Next we look at what action js cookie's with me. . <o:p> </ o: p ><!---->

Code bar code or direct quote that I find not his writing, not sure about it back to me. I write a simple point.

js code

  1. <Script type = "</ span"> "text / javascript">
  2. / / Write cookies function
  3. function SetCookie (name, value) / / two arguments, one cookie's name, one value
  4. (Var Days = 30;
  5. var exp = new Date (); / / new Date ("December 31, 9998");
  6. exp.setTime (exp.getTime () + Days * 24 * 60 * 60 * 1000); / / This cookie will be saved for 30 days
  7. document.cookie = name + "=" + escape (value) + "; expires =" + exp.toGMTString ();
  8. ) / / Escape be used to doing? Remember that to solve the Chinese problem.
  9. / / Above, even if the new definition of a cookie
  10. / / Get cookies function
  11. function getCookie (name)
  12. (
  13. var arr = document.cookie.match (new RegExp ("(^|) "+ name +"=([^;]*)(;|$)"));
  14. if (arr! = null) return unescape (arr [2]); return null;
  15. )
  16. / / Delete cookie
  17. function delCookie (name)
  18. (
  19. var exp = new Date ();
  20. exp.setTime (exp.getTime () - 1);
  21. var cval = getCookie (name);
  22. if (cval! = null) document.cookie = name + "=" + cval + "; expires =" + exp.toGMTString ();
  23. )
  24. SetCookie ("xiaoqi", "3")
  25. alert (getCookie ('xiaoqi'));
  26. </ Script>

<!----> 3. Operation cookie learned, what hard bargain. When the user opens the URL when you see getcookie, you will say how to judge it. This is indeed a problem. But not easy to solve. Directly taken out all the cookie to see if there is a cycle is equal to the last login time cookie setcookie name, you can name a complex point. Can determine whether there is the cookie name is complete. Principle is the case. Simple bar. Follow me correct. <o:p> </ o: p>

<!----> 4. Well. Set and get all difficult to learn what it hey what is difficult to find me on the pull. I am a responsible man haha. <o:p> </ o: p>

<!----> 5. Finally pull the code under the posts. I jsp judge directly, and then jump. More concise. Optimistic about it. <o:p> </ o: p>

jsp code

  1. login.jsp
  2. <%
  3. Cookie [] cookie = request.getCookies ();
  4. if (cookie! = null) (
  5. for (int i = 0; i <cookie.length; i + +) (
  6. Cookie myCookie = cookie [i];
  7. if (myCookie.getName (). equals ("usercookie")) (
  8. response.sendRedirect ("jump to a user interface");
  9. }}}%>

PS: "usercookie" is the first time logged into the cookie name. <o:p> </ o: p>

Haha So be it! <o:p> </ o: p>

Forget to write a bit with me to continue. . <o:p> </ o: p>

For example, if you do not want to use js cookie with java, then deposit is achievable. BS Let me directly quote the code a programmer could be easily understood Oh

java code

  1. Cookie usercookie = new Cookie ("usercookie", user.getUsername ());
  2. usercookie.setMaxAge (24 * 60 * 60);
  3. usercookie.setPath ("/ koubeiTest /");
  4. usercookie.setDomain ("www.lifeng.com");
  5. ServletActionContext.getResponse (). AddCookie (usercookie);

I need to explain setPath and setDomain Mody. Forget typing is tired. Do not understand themselves to check it

Panic. . . . <o:p> </ o: p>

<o:p> </ o: p>

<o:p> </ o: p>

<o:p> </ o: p>

<o:p> </ o: p>

相关文章
  • The automatic login cookie javascript 2010-04-18

    Written CssRain: http://www.cssrain.cn --- Marks <o:p> </ o: p> Cookie site or forum Automatic logon cookie technology is used most difficult to do. Haha with me was not difficult to <o:p> </ o: p> 1. We first look at the cookie to

  • Automatic login 139 E-mail 2010-09-01

    139 E-mail Yousha fun? Fetion can be used inside web; also can send text messages to any mobile phone; other 139i ties were good, but the cell phone address book and mail contacts synchronization. Automatic login is the first step, next step to be de

  • Digital automatic login School 2010-03-30

    Digital automatic login School

  • windows on the use of procedures using putty ssh automatic login linux (ubuntu) 2010-04-12

    Note: The following file name authorized_keys is not changed by other names! Method 1: Use puttygen.exe The first step: generating key run puttygen.exe, select the key type and length, use the default SSH2 (RSA), length of 1024 on it. passphrase can

  • Fedora13 automatic login 2010-05-27

    Backup cp / etc / gdm / gdm.schemas / etc / gdm / gdm.schemas.bkp Start editing File ... ... ... .. vim / etc / gdm / gdm.schemas Found `<schema> <key> daemon / AutomaticLoginEnable </ key> <signature> b </ signature> <def

  • [Linux server] automatic login using expect 2010-11-18

    Automatic login using expect First, what is expect? Doing system management, we often need to enter a password, for example: connection ssh, connect ftp, So how can do not enter a password? We need a tool that can replace the interaction that we achi

  • Simple plug-chrome, automatic login. 2010-12-08

    Today carried out a chrome plug, automatic login.'s First experience with chrome plug-in development, it seems pretty good, huh, huh ~ time to look after. manifest.json { "name": "auto login", "version": "1.0", &quo

  • Implement Linux (Ubuntu) on the automatic login and Ruijie Ruijie multiple versions (graphics and terminal)) 2010-11-08

    Suddenly found a slightly better open source revision Ruijie, http://code.google.com/p/mentohust/downloads/list , which provides many of which version to download, http://code.google.com / p / mentohust / wiki / Install This installation method provi

  • [Linux server] Using expect automatic login 2010-11-18

    Automatic login using expect First, what is expect? Do system management, we often need to enter a password, for example: connect ssh, connect ftp, So how can do not enter a password? We need a tool that can replace our interaction with the end to ac

  • Simple chrome plug, automatic login. 2010-12-08

    Today, out of a chrome plug, automatic login.'s First experience with chrome plug-in development, it seems pretty good, huh, huh - time to look after. manifest.json { "name": "auto login", "version": "1.0", "pe

  • linux automatic login to the desktop 2011-03-10

    Ubuntu by default each time you log is to enter a user name and password, it is reasonable to say that security considerations, but each time the login information for your computer or play with no safety concerns for users, it is bored, so we have t

  • [Transfer] license key: Automatic Login 2011-07-03

    "Red Hat Linux Guide: Server Setup and program design chapter" Chapter 1 OpenSSH: Secure Network Communications, This chapter discusses the components of the sshd (server daemon), ssh (running on the remote system command or log on to the remote

  • linux automatic login 2011-08-24

    linux automatic login Note that the corresponding backup file, this method will have no window border problem, I do not know how to solve temporary Method: The following package to the corresponding folder is probably where the original / etc / initt

  • Fedora15, Fedora16 root login and automatic login 2011-09-17

    root login vi / etc / pam.d / gdm Note which line auth required pam_succeed_if.so user! = Root quiet Then vi / etc / pam.d / gdm-password Note which line auth required pam_succeed_if.so user! = Root quiet Auto Login vi / etc / gdm / custom.conf In th

  • Add to delete cookie javascript js 2010-09-04

    <script language="JavaScript" type="text/javascript"> <!-- var Cookie=new Object(); Cookie.setCookie=function(name,value,option){ // Used to store assigned to the document.cookie cookie Format string var str=name+"="

  • Java code for automatic login function 2010-09-23

    Usually we log on a site, there will be Xuanze Baocunjitian, or a few weeks without Deng Lu, Zhihoushuru Gai website address Wuxudenglu Zhijiejinru Home Mian, Name That Jiaozuozidong login, how to achieve it, Xia Mian Xiao Li Zi I Yi 1 to demonstrate

  • [Transfer] automatic login with ssh public key linux server 2011-09-08

    [Transfer] http://7056824.blog.51cto.com/69854/403669 As a linux administrator, log on multiple Linux servers for remote operation is part of the work day. But with the increase in the server, each landing will be prompted to enter a user name and pa

  • Based on the user login page javascript validation 2009-11-16

    1, the user name can not contain spaces, the first letter can not be numbers, the length of control 2, password and authentication code to the same can not be empty, and so on, some very basic functionality, but it does Tingfan people. javascript deb

  • Provide the user name and password SSH automatic login script 2010-02-22

    Use VPN, repeated every time the input command in Terminal: ssh-D port user @ host Out the password prompt, to copy down a complex password, and then paste it into Terminal, hit Enter ... This finally could not bear repeating, and then use Shell to w

  • SSH automatic login, expect packages to be installed 2010-08-23

    ================================ #! / Usr / bin / expect set timeout 30 spawn ssh-l root 192.168.1.117 expect "password:" send "nopasswd \ r" interact ================================ set timeout 30 Sets the timeout, the time unit: sec