1

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. :\

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gavin
  • 31
  • 1
  • 6

2 Answers2

3
<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>

You can set the cookies as like

setCookie(test_cookie,5);

You can get the cookies as like

getCookie(test_cookie);

Hope it may helps to someone else. . .

Vignesh Pichamani
  • 7,950
  • 22
  • 77
  • 115
0

You don't need jQuery to read/write cookies. You can use plain javascript. Some good examples are here: http://www.quirksmode.org/js/cookies.html

You can use this jQuery plugin to make getting and setting cookies a little easier:

http://plugins.jquery.com/project/Cookie