OpenAI chat

1. Login-Seite aufrufen

HTTP Request

GET /login.php HTTP/1.1
Host: example.com

HTTP Response

HTTP/1.1 200 OK
Content-Type: text/html

<form method="POST" action="/login.php">
    <input name="username">
    <input name="password" type="password">
    <button>Login</button>
</form>

2. Login-Daten senden

HTTP Request

POST /login.php HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 35

username=alice&password=secret123

Der Browser sendet Benutzername und Passwort an den Server.


3. Server erstellt Session

Der Server:

Beispiel:

Session-ID:
8f3a91bca7d421e8d2...

HTTP Response

HTTP/1.1 302 Found
Location: /dashboard.php
Set-Cookie: PHPSESSID=8f3a91bca7d421e8d2;
             HttpOnly;
             Secure;
             SameSite=Lax

Der Browser speichert das Cookie automatisch.


5. Browser ruft geschützte Seite auf

HTTP Request

GET /dashboard.php HTTP/1.1
Host: example.com
Cookie: PHPSESSID=8f3a91bca7d421e8d2

Der Browser sendet das Cookie bei jeder passenden Anfrage automatisch mit.


6. Server erkennt den Benutzer

Der Server:

HTTP Response

HTTP/1.1 200 OK
Content-Type: text/html

<h1>Willkommen Alice</h1>

7. Weitere Requests

Alle weiteren Requests enthalten automatisch das Cookie.

HTTP Request

GET /profile.php HTTP/1.1
Host: example.com
Cookie: PHPSESSID=8f3a91bca7d421e8d2

Der Server kann den Benutzer erneut identifizieren.


8. Logout

HTTP Request

GET /logout.php HTTP/1.1
Host: example.com
Cookie: PHPSESSID=8f3a91bca7d421e8d2

Der Server löscht die Session.

HTTP Response

HTTP/1.1 302 Found
Location: /login.php
Set-Cookie: PHPSESSID=;
             Expires=Thu, 01 Jan 1970 00:00:00 GMT

Das Cookie wird im Browser gelöscht.


Ablaufübersicht

Browser                         Server
   |                               |
   | GET /login.php                |
   |------------------------------>|
   |                               |
   | HTML-Formular                 |
   |<------------------------------|
   |                               |
   | POST Benutzername/Passwort    |
   |------------------------------>|
   |                               |
   | Passwort prüfen               |
   | Session erzeugen              |
   | Session-ID speichern          |
   |                               |
   | Set-Cookie: PHPSESSID=...     |
   |<------------------------------|
   |                               |
   | Cookie speichern              |
   |                               |
   | GET /dashboard.php            |
   | Cookie: PHPSESSID=...         |
   |------------------------------>|
   |                               |
   | Session anhand Cookie finden  |
   | Benutzer erkennen             |
   |                               |
   | Geschützte Seite              |
   |<------------------------------|