Innhalt der PHP-Datei aufrufen und anzeigen
<script> function PHPcookiesAnzeigen() { const daten = "Zahl_1=Eins&Zahl_2=Zwei&Zahl_3=Drei"; const x = new XMLHttpRequest(); x.open("POST", "cookieTest.php"); x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); x.responseType = "text"; x.send(daten); x.onload = function() { document.getElementById("PHPausgabe").innerHTML = x.response; // jsDaten = x.response; }; } </script>
Quelltext von 'cookieTest.php'
<?php $i=1; foreach($_COOKIE as $key => $value) { echo "Cookie $i) Name = $key, Wert = $value<br>"; $i++; } echo "<br>Es hat " . count($_COOKIE) . " aktive Cookies"; ?>
Innhalt des JS-Scripts für die Cooki Auswertung und Anzeige
<script> function JScookieSetzen() { formLesen(); try { document.cookie = cookieString; } catch(e) { alert("Das Cookie " + cookieString + " konnte nicht gesetzt werden"); } } function JScookiesAnzeigen() { let a_guetzli = []; ausgabe = document.getElementById("JSausgabe"); ausgabe.innerHTML = ""; dc = document.cookie; if(dc.length < 1) { ausgabe.innerHTML += `<br>Es hat 0 aktive Cookies`; return; } g = dc.split(';'); for(i=0;i<g.length;i++) { a_guetzli[i] = []; a_guetzli[i] = g[i].split('='); ausgabe.innerHTML += `Cookie ${i+1}) Name = ${a_guetzli[i][0]}, Wert = ${a_guetzli[i][1]}<br>`; } ausgabe.innerHTML += `<br>Es hat ${g.length} aktive Cookies`; } </script>
Cookie wird gesetzt auf Domain-Angabe Sichtbar für example.com example.com example.com (nur Hauptdomain) example.com shop.example.com ❌ (ungültig) shop.example.com example.com example.com + alle Unterdomains shop.example.com shop.example.com shop.example.com (nur diese Unterdomain) example.com fremde.com ❌ (ungültig)
Attribut Same-Site Cross-Site Sicherheit Verwendung SameSite=None ✅ Ja ✅ Ja Niedrig Drittanbieter-Cookies (eingebettete Inhalte) Kein oder Lax ✅ Ja ❌ Nein Mittel Standard-Cookies für die eigene Website SameSite=Strict ✅ Ja ❌ Nein Hoch Sensible Cookies (Authentifizierung)