本文介绍了如何保存cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人说他们直接登录到我的网站,我该怎么办?
我将如何到达该位置,一旦他们登录,他们实际上是通过Cookie登录的?
这样说。
如果您想真正地完全访问您注册并登录的网站,但是一旦登录将保存cookie,则注销。
目前,我已经注册并登录,但是它没有保存cookie。 :\

How would I go about having people that say they directly login to my website,How would I make it to where, Once they login they are actually loged in via cookies? To say something like this."If you would like to actually completely access the website you signup and login, But once you login it saves your cookies, Intill loging out." At the moment, I have the signup and the login but it's not saving the cookies. :\

推荐答案

<script type="text/javascript">

        function setCookie(key, value) {
            var expires = new Date();
            expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
            document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
        }

        function getCookie(key) {
            var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
            return keyValue ? keyValue[2] : null;
        }
</script>

您可以将Cookie设置为

You can set the cookies as like

setCookie(test_cookie,5);

您可以像获得饼干一样

getCookie(test_cookie);

希望对别人有帮助。 。 。

Hope it may helps to someone else. . .

这篇关于如何保存cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 07:26