Doubt about variable cookies and JS

Asked

Viewed 44 times

0

You can create a variable in javascript or jquery and store cookies in it for a certain time X?

  • 3

    You are referring to the use of cookies?

  • @Máttheusspoo I think that would be the right name

  • Can use localstorage, it depends a lot what you want to do..

  • You need to explain what you want best. In JS it is possible, in jQuery you cannot because it is not a programming language and has no variables. But there’s no point in keeping one cookie in a variable, especially if you want to cache. You can store a value in a cookie. If it’s anything more complex, then you need localstorage, but we don’t know what you need.

  • @Fbor I want to store ip + date to add it all up and create like an ID for x minutes and use in an api

  • @Maniero This is basically what you said I need to create a cookie stored for X time to use in some other functions.

  • Using cookie is sometimes bad because the customer can delete or block when they want.

  • 1

    the user’s IP and date are already accessible on the server side, I do not see the need to store it in a Cookie. as for access control, you should not rely on data that can be edited on the client side, so I advise you to use jwt with Encryption, and store it on the localStorage. thus, sensitive user data could be part of the token.

  • I recommend using another type of identification, this model is very flawed, but if you need to use it, you can save in Localstorage with your skills.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.