57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
|
<?php
|
||
|
session_start();
|
||
|
|
||
|
if (isset($_POST['end'])) {
|
||
|
echo 'koniec sesji</br>';
|
||
|
echo 'suma: ' . $_SESSION['sum'] . '</br>';
|
||
|
echo 'srednia: ' . $_SESSION['avg'] . '</br>';
|
||
|
echo 'przesłane liczby: ' . $_SESSION['num'] . '</br>';
|
||
|
echo 'liczba przesłanych liczb: ' . $_SESSION['cnt'] . '</br>';
|
||
|
|
||
|
session_unset();
|
||
|
session_destroy();
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
if (isset($_POST['user'])) {
|
||
|
$_SESSION['user'] = $_POST['user'];
|
||
|
echo 'Witaj ' . $_SESSION['user'] . '!</br></br>';
|
||
|
}
|
||
|
|
||
|
if (!isset($_SESSION['user'])) {
|
||
|
echo '<h3>Witam witam witam</h3>';
|
||
|
echo '<form action="/srednia.php" method="post">';
|
||
|
echo ' <input type="text" name="user">';
|
||
|
echo ' <button type="submit">Przywitaj się!</button>';
|
||
|
echo '</form>';
|
||
|
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
if (isset($_POST['number'])) {
|
||
|
$_SESSION['cnt'] += 1;
|
||
|
$_SESSION['sum'] += $_POST['number'];
|
||
|
$_SESSION['num'] .= $_POST['number'] . ', ';
|
||
|
$_SESSION['avg'] = $_SESSION['sum'] / $_SESSION['cnt'];
|
||
|
}
|
||
|
|
||
|
echo 'suma: ' . $_SESSION['sum'] . '</br>';
|
||
|
echo 'srednia: ' . $_SESSION['avg'] . '</br>';
|
||
|
echo 'przesłane liczby: ' . $_SESSION['num'] . '</br>';
|
||
|
echo 'liczba przesłanych liczb: ' . $_SESSION['cnt'] . '</br>';
|
||
|
|
||
|
echo '<h4>Obliczanie</h4>';
|
||
|
echo '<form action="/srednia.php" method="post">';
|
||
|
echo ' <input type="number" name="number">';
|
||
|
echo ' <button type="submit">Dodaj!</button>';
|
||
|
echo '</form>';
|
||
|
|
||
|
echo '<br>';
|
||
|
|
||
|
echo '<h5>Koniec sesji?</h5>';
|
||
|
echo '<form action="/srednia.php" method="post">';
|
||
|
echo ' <button name="end" value="end" type="submit">Tak!</button>';
|
||
|
echo '</form>';
|
||
|
|
||
|
?>
|