HW start
This commit is contained in:
parent
f394538776
commit
cceab89523
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
ini_set("display_errors", 1);
|
||||
ini_set("default_charset", "utf-8");
|
||||
error_reporting(E_ALL);
|
||||
@ -14,7 +14,7 @@ class Headers
|
||||
|
||||
static function redirect(string $newUrl, bool $permanent = FALSE)
|
||||
{
|
||||
header('Location: ' . $newUrl, true, $permanent ? 301 : 302);
|
||||
header('Location: ' . $newUrl, true, $permanent ? 301 : 303);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
7
base/settings.php
Normal file
7
base/settings.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
ini_set("display_errors", 1);
|
||||
ini_set("default_charset", "utf-8");
|
||||
ini_set('session.cookie_httponly', 1);
|
||||
ini_set('session.cookie_secure', 1);
|
||||
ini_set('session.use_only_cookies', 1);
|
||||
error_reporting(E_ALL);
|
||||
46
homework/colourSelector/index.php
Normal file
46
homework/colourSelector/index.php
Normal file
@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<?php include_once "../../base/meta.php" ?>
|
||||
|
||||
<title>Colour Selector</title>
|
||||
|
||||
<script src="./js/formValidation.js"></script>
|
||||
|
||||
<?php
|
||||
// PHP
|
||||
include_once "../../base/settings.php";
|
||||
include_once "../../base/headers.php";
|
||||
|
||||
if (isset($_POST["colour"])) {
|
||||
$colour = $_POST["colour"];
|
||||
|
||||
if (preg_match("^#([0-9A-Fa-f]{3,4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$", $colour) === false) {
|
||||
$error = "Invalid hex colour";
|
||||
}
|
||||
}
|
||||
|
||||
Headers::html();
|
||||
?>
|
||||
</head>
|
||||
|
||||
<body style="background-color: <?=$colour?>">
|
||||
|
||||
<div class="form-check form-switch m-3">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="clientSideValidate">
|
||||
<label class="form-check-label" for="clientSideValidate">Use Client Side Validation</label>
|
||||
</div>
|
||||
<form method="post" class="needs-validation row m-0" novalidate>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="colour">Colour Code</label>
|
||||
<input class="form-control" id="colour" name="colour" required pattern="^#([0-9A-Fa-f]{3,4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$" />
|
||||
<div class="invalid-feedback">
|
||||
Please enter valid hex colour code
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary mt-3" name="firstLoad" value="0">Berechnen</button>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
33
homework/colourSelector/js/formValidation.js
Normal file
33
homework/colourSelector/js/formValidation.js
Normal file
@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const _switch = document.getElementById("clientSideValidate");
|
||||
_switch.addEventListener("change", () =>
|
||||
_switch.checked ? addValidation() : removeValidation()
|
||||
);
|
||||
});
|
||||
|
||||
const handler = (event) => {
|
||||
if (!event.target.checkValidity()) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
event.target.classList.add("was-validated");
|
||||
};
|
||||
|
||||
const addValidation = () => {
|
||||
const forms = document.querySelectorAll(".needs-validation");
|
||||
|
||||
Array.from(forms).forEach((form) => {
|
||||
form.addEventListener("submit", handler, false);
|
||||
});
|
||||
};
|
||||
|
||||
const removeValidation = () => {
|
||||
const forms = document.querySelectorAll(".needs-validation");
|
||||
|
||||
Array.from(forms).forEach((form) => {
|
||||
form.removeEventListener("submit", handler, false);
|
||||
});
|
||||
};
|
||||
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<?php include_once "../../base/meta.php" ?>
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
<body>
|
||||
<?php
|
||||
include_once "../../base/errors.php";
|
||||
include_once "../../base/settings.php";
|
||||
include_once "../../base/headers.php";
|
||||
Headers::html();
|
||||
|
||||
|
||||
1
tasks/counter/data/counter.txt
Normal file
1
tasks/counter/data/counter.txt
Normal file
@ -0,0 +1 @@
|
||||
20
|
||||
36
tasks/counter/index.php
Normal file
36
tasks/counter/index.php
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<?php include_once "../../base/meta.php" ?>
|
||||
|
||||
<title>Counter</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
// PHP
|
||||
include_once "../../base/settings.php";
|
||||
include_once "../../base/headers.php";
|
||||
|
||||
$fh = fopen("./data/counter.txt", "r+");
|
||||
if (flock($fh, LOCK_EX)) {
|
||||
$cnt = intval(fgets($fh));
|
||||
|
||||
if (!isset($_COOKIE["counter-visit"])) {
|
||||
rewind($fh);
|
||||
$cnt += 1;
|
||||
fputs($fh, strval($cnt));
|
||||
|
||||
setcookie("counter-visit", "true", ["expires" => time() + 60 * 60 * 24, "samesite" => "strict", "secure" => true, "httponly" => true]);
|
||||
}
|
||||
}
|
||||
flock($fh, LOCK_UN);
|
||||
fclose($fh);
|
||||
|
||||
Headers::html();
|
||||
?>
|
||||
<h1>Visitor count: <?= $cnt ?></h1>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
include_once "../../../base/errors.php";
|
||||
include_once "../../../base/settings.php";
|
||||
include_once "../../../base/headers.php";
|
||||
|
||||
session_start();
|
||||
|
||||
@ -1 +1 @@
|
||||
[{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715338381,"title":"sdf","name":"dsaf","comment":"dsg"},{"time":1715339761,"title":"Witzige Aufgabe","name":"Kilian","comment":"nun ja, also das funktioniert ja schon recht gut gell."},{"time":1716539658,"title":"Progress Bar","name":"Kilian","comment":"Jetzt auch mit einem etwas geileren Progress Bar der einem die Character-Anzahl anzeigt.\r\nWesentlich geiler, wesentlich nicer, und Bootstraped"},{"time":1716541941,"title":"New layout","name":"Kilian","comment":"New folder structure"},{"time":1716545229,"title":"More consistent padding","name":"Kilian","comment":"More unified padding across the sections of the page"},{"time":1716545296,"title":"Inject","name":"Kilian","comment":"<?php echo \"injection time!\" ?>"},{"time":1716546110,"title":"JS Inject","name":"Kilian","comment":"<script>\r\nconsole.log(\"BAD\");\r\n<\/script\/>"}]
|
||||
[{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715338381,"title":"sdf","name":"dsaf","comment":"dsg"},{"time":1715339761,"title":"Witzige Aufgabe","name":"Kilian","comment":"nun ja, also das funktioniert ja schon recht gut gell."},{"time":1716539658,"title":"Progress Bar","name":"Kilian","comment":"Jetzt auch mit einem etwas geileren Progress Bar der einem die Character-Anzahl anzeigt.\r\nWesentlich geiler, wesentlich nicer, und Bootstraped"},{"time":1716541941,"title":"New layout","name":"Kilian","comment":"New folder structure"},{"time":1716545229,"title":"More consistent padding","name":"Kilian","comment":"More unified padding across the sections of the page"},{"time":1716545296,"title":"Inject","name":"Kilian","comment":"<?php echo \"injection time!\" ?>"},{"time":1716546110,"title":"JS Inject","name":"Kilian","comment":"<script>\r\nconsole.log(\"BAD\");\r\n<\/script\/>"},{"time":1716547636,"title":"Redirect","name":"Kilian","comment":"Correct redirect tag"},{"time":1716547857,"title":"Back to old","name":"Kilian","comment":"302 is apparently more common"}]
|
||||
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<?php include_once "../../base/meta.php" ?>
|
||||
@ -15,7 +15,7 @@
|
||||
// HTML
|
||||
include_once "../../base/icons.php";
|
||||
// PHP
|
||||
include_once "../../base/errors.php";
|
||||
include_once "../../base/settings.php";
|
||||
include_once "../../base/headers.php";
|
||||
|
||||
session_start();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
include_once "../../base/errors.php";
|
||||
include_once "../../base/settings.php";
|
||||
include_once "../../base/headers.php";
|
||||
Headers::html();
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
include_once "../base/errors.php";
|
||||
include_once "../base/settings.php";
|
||||
include_once "../base/headers.php";
|
||||
include_once "../base/database.php";
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<?php include_once "../../base/meta.php" ?>
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
<body>
|
||||
<?php
|
||||
include_once "../base/errors.php";
|
||||
include_once "../base/settings.php";
|
||||
include_once "../base/headers.php";
|
||||
Headers::html();
|
||||
include_once "../base/database.php";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user