24.09
This commit is contained in:
30
Tematy/T59a - data ostatnich odwiedzin na stronie/index.php
Normal file
30
Tematy/T59a - data ostatnich odwiedzin na stronie/index.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<!doctype html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>T59a</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Zadanie T59a</h1>
|
||||
<h2>Autor: Jakub Grzegorczyk</h2>
|
||||
</header>
|
||||
<div class="box">
|
||||
<p>Napisz skrypt tworzący plik cookie wizyta - określający datę ostatnich odwiedzin strony przez użytkownika oraz skrypt odczytujący tę informację.</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<?php
|
||||
setcookie("wizyta", date("Y-m-d H:i:s"), time() + 3600);
|
||||
|
||||
if (isset($_COOKIE["wizyta"])) {
|
||||
echo "Ostatnia wizyta: " . $_COOKIE["wizyta"];
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
68
Tematy/T59a - data ostatnich odwiedzin na stronie/style.css
Normal file
68
Tematy/T59a - data ostatnich odwiedzin na stronie/style.css
Normal file
@@ -0,0 +1,68 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: Verdana, serif;
|
||||
background: #ffffff;
|
||||
margin: 15px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
header {
|
||||
border: 2px solid black;
|
||||
border-radius: 1em;
|
||||
padding: 10px 20px;
|
||||
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
input {
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
width: 30%;
|
||||
border: black 2px solid;
|
||||
border-radius: 0.5em;
|
||||
height: 2em;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 5px;
|
||||
width: 30%;
|
||||
border: black 2px solid;
|
||||
border-radius: 0.5em;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
}
|
||||
pre {
|
||||
font-family: Verdana, serif;
|
||||
}
|
||||
|
||||
.box {
|
||||
border: 2px solid black;
|
||||
padding: 15px 20px;
|
||||
border-radius: 1em;
|
||||
margin: 15px 0 10px 0;
|
||||
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
|
||||
}
|
||||
|
||||
.box h3 {
|
||||
cursor: pointer;
|
||||
}
|
||||
td {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
tr {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.y {
|
||||
background: yellow;
|
||||
}
|
||||
|
||||
.b {
|
||||
background:blue;
|
||||
}
|
||||
|
||||
|
||||
78
Tematy/T59b - przesyłanie danych użytkownika/index.php
Normal file
78
Tematy/T59b - przesyłanie danych użytkownika/index.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<!doctype html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>T59b</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Zadanie T59b</h1>
|
||||
<h2>Autor: Jakub Grzegorczyk</h2>
|
||||
</header>
|
||||
<div class="box">
|
||||
<p>PHP Przesyłanie danych użytkownika <br><br>
|
||||
|
||||
(Podstawowa wersja rozwiązania) <br>
|
||||
Utwórz skrypt, który dane użytkownika przesyłane za pomocą formularza będzie przekazywał do utworzonego pliku cookie. Formularz powinien zawierać imię i nazwisko użytkownika.
|
||||
<br><br>
|
||||
|
||||
(Wersja rozszerzona)<br>
|
||||
|
||||
Dodatkowo przekazana jest również data urodzin użytkownika. Skrypt powinien wyświetlać informację, za ile dni użytkownik będzie obchodził urodziny.</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<form action="index.php" method="post">
|
||||
<label for="imie">Imie: </label><br>
|
||||
<input type="text" name="imie" id="imie"><br>
|
||||
<label for="nazwisko">Nazwisko: </label><br>
|
||||
<input type="text" name="nazwisko" id="nazwisko"><br>
|
||||
<label for="data">Data urodzin: </label><br>
|
||||
<input type="date" name="data" id="data"><br>
|
||||
<button type="submit">Wyślij</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="box">
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
setcookie('imie', $_POST['imie'], time() + 3600);
|
||||
setcookie('nazwisko', $_POST['nazwisko'], time() + 3600);
|
||||
setcookie('data', $_POST['data'], time() + 3600);
|
||||
}
|
||||
if (isset($_COOKIE['imie']) && isset($_COOKIE['nazwisko']) && isset($_COOKIE['data'])) {
|
||||
function daysUntilNextBirthday(string $birthDate): ?int
|
||||
{
|
||||
$parts = explode('-', $birthDate);
|
||||
if (count($parts) !== 3) {
|
||||
return null;
|
||||
}
|
||||
$now = time();
|
||||
$currentYear = (int)date('Y');
|
||||
|
||||
$parts[0] = (string)$currentYear;
|
||||
$candidate = implode('-', $parts);
|
||||
$target = strtotime($candidate);
|
||||
if ($target === false) {
|
||||
return null;
|
||||
}
|
||||
if ($target < $now) {
|
||||
$parts[0] = (string)($currentYear + 1);
|
||||
$candidate = implode('-', $parts);
|
||||
$target = strtotime($candidate);
|
||||
if ($target === false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return (int)ceil(($target - $now) / 86400);
|
||||
}
|
||||
echo "Witaj " . $_COOKIE['imie'] . " " . $_COOKIE['nazwisko'];
|
||||
echo "<br>";
|
||||
echo "Twoje urodziny będą za " . (daysUntilNextBirthday($_COOKIE['data'])) . " dni.";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
68
Tematy/T59b - przesyłanie danych użytkownika/style.css
Normal file
68
Tematy/T59b - przesyłanie danych użytkownika/style.css
Normal file
@@ -0,0 +1,68 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: Verdana, serif;
|
||||
background: #ffffff;
|
||||
margin: 15px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
header {
|
||||
border: 2px solid black;
|
||||
border-radius: 1em;
|
||||
padding: 10px 20px;
|
||||
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
input {
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
width: 30%;
|
||||
border: black 2px solid;
|
||||
border-radius: 0.5em;
|
||||
height: 2em;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 5px;
|
||||
width: 30%;
|
||||
border: black 2px solid;
|
||||
border-radius: 0.5em;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
}
|
||||
pre {
|
||||
font-family: Verdana, serif;
|
||||
}
|
||||
|
||||
.box {
|
||||
border: 2px solid black;
|
||||
padding: 15px 20px;
|
||||
border-radius: 1em;
|
||||
margin: 15px 0 10px 0;
|
||||
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
|
||||
}
|
||||
|
||||
.box h3 {
|
||||
cursor: pointer;
|
||||
}
|
||||
td {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
tr {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.y {
|
||||
background: yellow;
|
||||
}
|
||||
|
||||
.b {
|
||||
background:blue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user