JWT vs cookies for token-based authentication

The biggest difference between bearer tokens and cookies is that the browser will automatically send cookies, where bearer tokens need to be added explicitly to the HTTP request. This feature makes cookies a good way to secure websites, where a user logs in and navigates between pages using links. The browser automatically sending cookies also … Read more

How to set a cookie for another domain

You cannot set cookies for another domain. Allowing this would present an enormous security flaw. You need to get b.com to set the cookie. If a.com redirect the user to b.com/setcookie.php?c=value The setcookie script could contain the following to set the cookie and redirect to the correct page on b.com <?php setcookie(‘a’, $_GET[‘c’]); header(“Location: b.com/landingpage.php”); … Read more

Chrome doesn’t delete session cookies

This can be caused by having Chrome set to Continue where you left off. Further reading Bug report: Chrome is not deleting temporary cookies – i.e. not logging me out automatically when I close all browser Windows Issue 128513 in Chromium: Session Cookies not cleared when Chrome processes closed Issue 128567: Session only cookies don’t … Read more

Create, read, and erase cookies with jQuery [duplicate]

Use JavaScript Cookie plugin Set a cookie Cookies.set(“example”, “foo”); // Sample 1 Cookies.set(“example”, “foo”, { expires: 7 }); // Sample 2 Cookies.set(“example”, “foo”, { path: ‘/admin’, expires: 7 }); // Sample 3 Get a cookie alert( Cookies.get(“example”) ); Delete the cookie Cookies.remove(“example”); Cookies.remove(‘example’, { path: ‘/admin’ }) // Must specify path if used when setting.

Cookies vs. sessions

The concept is storing persistent data across page loads for a web visitor. Cookies store it directly on the client. Sessions use a cookie as a key of sorts, to associate with the data that is stored on the server side. It is preferred to use sessions because the actual values are hidden from the … Read more

Set a cookie to never expire

All cookies expire as per the cookie specification, so this is not a PHP limitation. Use a far future date. For example, set a cookie that expires in ten years: setcookie( “CookieName”, “CookieValue”, time() + (10 * 365 * 24 * 60 * 60) ); Note that if you set a date past 2038 in … Read more

What is the shortest function for reading a cookie by name in JavaScript?

Shorter, more reliable and more performant than the current best-voted answer: const getCookieValue = (name) => ( document.cookie.match(‘(^|;)\\s*’ + name + ‘\\s*=\\s*([^;]+)’)?.pop() || ” ) A performance comparison of various approaches is shown here: https://jsben.ch/AhMN6 Some notes on approach: The regex approach is not only the fastest in most browsers, it yields the shortest function … Read more

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