Cookies i pamiętane dane
Jeśli chcemy, aby formularz był częściowo wypełniony – używamy „ciasteczek” (cookies) [30].
<?php
include "ex28m.php"; // model
$books = modelPobierz();
$nowa = isset($_GET['title']) || isset($_GET['authors']);
if ($nowa) {
modelNowa($books, $_GET['title'], $_GET['authors']);
$authors=$_GET['authors'];
setcookie('authors', $authors, time() + 86400); // na 1 godzinę
} else {
$authors = htmlspecialchars($_COOKIE['authors']);
}
include "ex30v.php";
W pliku widoku (na ex30v - na bazie ex28v.php) zmieniamy jeden wiersz:
<div>Autorzy:<inputtype="text"name="authors"value="<?=$authors?>"/></div>
Tablica $_COOKIE należy do tak zwanych „superglobals”:
http://php.net/manual/en/language.variables.superglobals.php
$_GET – z formularza GET
$_POST – z formularza POST
$_COOKIE – ciasteczka
$_SERVER – dane serwera
$_REQUEST – $_GET, $_POST i $_COOKIE razem