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. :\
Asked
Active
Viewed 7,801 times
1
-
ooo @ epascarello, I didn't see that, Thank you! – Gavin Nov 26 '13 at 18:38
2 Answers
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:
Vahid Taghizadeh
- 997
- 8
- 9