Apprendre PHP (13/19) - Manipulation des cookies

25 Mar 2019 · 9 min
8:56

In this French‑language tutorial, the instructor explains the relationship between PHP sessions and HTTP cookies, emphasizing that a session ID is stored in a cookie to link the client to server‑side session data. He advises using sessions for sensitive information (logins, passwords) and reserving cookies for non‑critical data such as shopping‑cart contents or UI preferences. The core example demonstrates how to let a user choose a light or dark site theme and persist that choice with a cookie. The lesson walks through retrieving a ‘theme’ GET parameter, validating it, creating a cookie with setcookie(name, value, expiration) (using time()+3600 for a one‑hour lifetime), reading the cookie via the $_COOKIE superglobal, applying the stored value to select the appropriate CSS file (clair.css or sombre.css), handling the default theme with a ternary operator and the @ error‑suppression operator, and finally issuing a header('Location: …') redirect to avoid double‑click issues and ensure the cookie is sent before the page reloads. The instructor repeatedly tests the flow, clears browser history, and shows that the chosen theme persists across page loads.

Chapters

More from Yamossoun

8:56
youtube.com

Compteur synchrone - Logique séquentielle

2w ago
11:58
youtube.com

Compteur asynchrone et diviseur de fréquence - Logique séquentielle

3w ago
11:37
youtube.com

Les registres (parallèle et à décalage) - Logique séquentielle

1mo ago
6:14
youtube.com

Bascule T (Toggle) - Logique séquentielle

1mo ago
12:05
youtube.com

Bascule JK - Logique séquentielle

1mo ago
9:17
youtube.com

Bascule D flip-flop active sur front montant - Logique séquentielle

1mo ago
10:08
youtube.com

Bascule D Latch - Logique séquentielle

1mo ago
8:13
youtube.com

Bascule RS - Logique séquentielle

1mo ago
5:04
youtube.com

Logique séquentielle - Introduction

2mo ago
1:15
youtube.com

Le codeur - Logique combinatoire #codeur #logique #circuit #booleanlogic

2mo ago
1:56
youtube.com

Algorithme de calcule de la racine carrée par dichotomie #dichotomy #squareroot #algorithm

3mo ago
See all content