Local Storage vs Cookies

Cookies and local storage serve different purposes. Cookies are primarily for reading server-side, local storage can only be read by the client-side. So the question is, in your app, who needs this data — the client or the server? If it’s your client (your JavaScript), then by all means switch. You’re wasting bandwidth by sending … Read more

Check if a PHP cookie exists and if not set its value

Answer You can’t according to the PHP manual: Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays. This is because cookies are sent in response headers to the browser and the browser must then send them back with the next request. This is … Read more

What is the difference between localStorage, sessionStorage, session and cookies?

This is an extremely broad scope question, and a lot of the pros/cons will be contextual to the situation. In all cases, these storage mechanisms will be specific to an individual browser on an individual computer/device. Any requirement to store data on an ongoing basis across sessions will need to involve your application server side … Read more

Cross-Domain Cookies

I have two webapps WebApp1 and WebApp2 in two different domains. I am setting a cookie in WebApp1 in the HttpResponse. How to read the same cookie from HttpRequest in WebApp2? I know it sounds weird because cookies are specific to a given domain, and we can’t access them from different domains; I’ve however heard … Read more

Get cookie by name

I have a getter to get the value from a cookie. Now I have 2 cookies by the name shares= and by the name obligations= . I want to make this getter only to get the values from the obligations cookie. How do I do this? So the for splits the data into separate values … Read more

How do I expire a PHP session after 30 minutes?

You should implement a session timeout of your own. Both options mentioned by others (session.gc_maxlifetime and session.cookie_lifetime) are not reliable. I’ll explain the reasons for that. First: session.gc_maxlifetimesession.gc_maxlifetime specifies the number of seconds after which data will be seen as ‘garbage’ and cleaned up. Garbage collection occurs during session start. But the garbage collector is … Read more

How do I set/unset a cookie with jQuery?

Update April 2019 jQuery isn’t needed for cookie reading/manipulation, so don’t use the original answer below. Go to https://github.com/js-cookie/js-cookie instead, and use the library there that doesn’t depend on jQuery. Basic examples: See the docs on github for details. Before April 2019 (old) See the plugin: You can then do: To delete: Additionally, to set a timeout … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)