Technológie internetuInternet Technologies / Týždeň 12Week 12

Moderný web a AIThe modern web and AI

Moderný web má jasnú štruktúru, vie ho použiť každý a je bezpečný. Táto stránka ukazuje, čo tieto vlastnosti znamenajú, kde ich aplikácia z cv01 až cv10 už má a akými nástrojmi sa dnes web píše. Stránka je na čítanie, úlohy na odovzdanie nemá. Pojmy sú v tabuľke v týždni 1.

A modern web site has a clear structure, everyone can use it and it is secure. This page shows what these properties mean, where the application from cv01 to cv10 already has them and which tools are used to write for the web today. The page is for reading; it has no tasks to submit. Terms are in the table in week 1. Comments in the code and texts in the previews are in Slovak.

TeóriaTheory

Vlastnosti moderného webu

Vlastnosť Čo znamená Kde to v aplikácii už je
jasná štruktúra každá vec je na jednom mieste a dá sa nájsť file stránky, template.php, content file, css/style.css, js/app.js
prístupnosť web vie použiť aj človek, ktorý zle vidí, pracuje bez myši alebo je v priestore s nevhodným osvetlením label pre každý input, alt pre každý obrázok, Bootstrap
bezpečnosť vstup od používateľa sa spracuje ako text a heslá sú uložené ako hash htmlspecialchars, prepare, password_hash

Jasná štruktúra: ako sa stránka skladá

Po otvorení adresy .../web/routes.php sa vykoná file stránky, ten pripojí template.php a template vloží content file:

…/web/routes.php
routes.php file stránky: pripojí db.php, nastaví $title, $active, $content
template.php kostra: <head> s $title, menu so zvýraznením podľa $active, <h1>, footer, js/app.js
content/routes.php obsah: SELECT a výpis

Každá vrstva má svoj file a svoju úlohu:

Vrstva Úloha Kde je
HTML obsah a jeho význam content files, template.php
CSS vzhľad Bootstrap a css/style.css
JavaScript čo sa stane po kliknutí alebo pri písaní js/app.js
PHP a SQL údaje file stránky, content file, databáza

Vzhľad sa mení v CSS, údaje v PHP a SQL. Zmena v jednej vrstve nechá ostatné vrstvy bez zmeny.

K štruktúre patrí aj význam tagov. Prehliadač, vyhľadávač aj čítačka obrazovky sa podľa nich orientujú:

<header>...</header>            <!-- hlavička webu -->
<nav>...</nav>                  <!-- menu; čítačka obrazovky naň vie skočiť -->
<main>                          <!-- hlavný obsah stránky, na stránke je raz -->
  <h1>Cesty</h1>                <!-- hlavný nadpis, na stránke je raz -->
  <h2>Nové cesty</h2>           <!-- podnadpis; po h1 nasleduje h2, po h2 h3 -->
</main>
<footer>...</footer>            <!-- päta webu -->

Stránka poskladaná len z <div> vyzerá v prehliadači rovnako ako táto, ale čítačka obrazovky v nej menu ani hlavný obsah nenájde.

Redakčný systém (CMS)

Redakčný systém, po anglicky Content Management System, je hotová aplikácia, v ktorej sa obsah webu píše cez formuláre v prehliadači. Kto píše články, pracuje len s formulármi v administrácii. Najrozšírenejší je WordPress. Vydali ho v roku 2003 Matt Mullenweg a Mike Little, je open source a je napísaný v PHP s databázou MySQL.

V aplikácii V redakčnom systéme
template.php téma (theme): hotový vzhľad, ktorý sa dá vymeniť
table v databáze a content file s výpisom články a stránky uložené v databáze
add-ENTITY.php, edit-ENTITY.php editor v administrácii
prihlásenie z cv09 účty s rolami: redaktor píše, administrátor nastavuje

Redakčný systém sa hodí na web s článkami, novinkami a stránkami. Na evidenciu s vlastnými tables, ako je aplikácia z cvičení, sa píše vlastná aplikácia.

Vlastná aplikácia sa v praxi píše pomocou hotového kódu od iných autorov:

V aplikácii Čím sa to robí v praxi Čo to je
template.php a content files Laravel, Symfony framework pre PHP: hotové skladanie stránok, prihlásenie, kontrola formulárov
SQL cez PDO Eloquent, Doctrine ORM: record z table je v PHP objekt a SQL napíše knižnica
Bootstrap Bootstrap, Tailwind hotové classes pre vzhľad
js/app.js Vue, React knižnice, ktoré menia elementy stránky podľa údajov

Všetky sú open source: ich kód je verejný a používanie je bezplatné.

Prístupnosť: štandard WCAG

WCAG (Web Content Accessibility Guidelines) je štandard, ktorý hovorí, čo musí web spĺňať, aby ho vedel použiť každý. Vydáva ho konzorcium W3C, ktoré vydáva aj štandardy HTML a CSS. Platná verzia je 2.2. Má úrovne A, AA a AAA. Bežne sa vyžaduje úroveň AA.

Na Slovensku je prístupnosť povinná:

Pre koho Predpis Čo vyžaduje
weby verejnej správy zákon č. 95/2019 Z. z. a vyhláška č. 78/2020 Z. z. WCAG 2.1, úrovne A a AA
e-shopy a ďalšie služby pre spotrebiteľov, napríklad finančné a dopravné zákon č. 351/2022 Z. z., účinný od 28. júna 2025 prístupný web a mobilná aplikácia; mikropodniky do 10 zamestnancov majú výnimku

Farby a kontrast

Kontrast je pomer jasu textu a pozadia. Čierna na bielej má pomer 21 : 1, dve rovnaké farby 1 : 1.

Čo Najmenší kontrast pre úroveň AA
bežný text 4,5 : 1
veľký text: od 24 px, alebo tučný od 18,5 px 3 : 1
ikony a rámik, ktorý má input 3 : 1

Text veľkosti 16 px v rôznych farbách na bielom pozadí:

Náhľad
Ukážkový text na bielom pozadí#21252915,43 : 1vyhovuje
Ukážkový text na bielom pozadí#6c757d4,69 : 1vyhovuje tesne
Ukážkový text na bielom pozadí#adb5bd2,07 : 1nevyhovuje
Ukážkový text na bielom pozadí#ffc1071,63 : 1nevyhovuje

Pravidlo o farbe: informácia je na stránke vždy aj ako text. Kto nerozlišuje červenú a zelenú, červený rámik nevidí.

<!-- zle: chybu oznamuje len červený rámik -->
<input class="form-control is-invalid" name="email">

<!-- dobre: rámik a k nemu text, ktorý povie, čo je zle -->
<input class="form-control is-invalid" name="email">
<div class="invalid-feedback">E-mail nemá správny tvar.</div>

Kontrast ukáže prehliadač: F12, karta Elements, kliknúť na element s textom a v pravej časti panela na farebný štvorček pri color. Zobrazí sa pomer a značka, či vyhovuje.

Zásady webdizajnu

Zásada Čo znamená V aplikácii s Bootstrap
hierarchia jeden h1, pod ním h2, potom h3 <h1> s $title v template.php
mriežka obsah je zarovnaný do stĺpcov container, row, col-md-6
voľné miesto medzi časťami stránky je medzera mb-3, g-3, py-4
dĺžka riadku 45 až 75 znakov; dlhší riadok sa zle číta text v col-lg-8
písmo najviac dve písma, bežný text aspoň 16 px predvolené písmo Bootstrap
jednotnosť rovnaká akcia vyzerá na každej stránke rovnako btn-primary hlavná akcia, btn-outline-secondary späť, btn-outline-danger zmazať
farby jedna hlavná, jedna na upozornenie, ostatné sivé farby Bootstrap
mobil ako prvý stránka sa navrhuje pre úzku obrazovku a pre širokú sa rozširuje col-md-, navbar-expand-md
odkazy text odkazu hovorí, kam vedie „detail cesty” namiesto „klikni sem”
formuláre label nad každý input, hláška hneď pod input, povinný input označený slovom „povinné” form-label, invalid-feedback

Ten istý formulár bez zásad a podľa zásad:

Náhľad

Zle

OK

Dobre

E-mail nemá správny tvar, chýba časť za znakom @.

Odoslať prihlášku

Vľavo chýba label, text má kontrast 2,07 : 1, chybu oznamuje len farba rámika a button nehovorí, čo spraví.

Kontrola: Lighthouse

Lighthouse je nástroj v prehliadači Chrome, ktorý stránku ohodnotí. Postup: otvoriť aplikáciu vo svojom webovom priestore na sigma.tuke.sk, stlačiť F12, v rade kariet vybrať Lighthouse (môže byť schovaná pod ») a kliknúť na button Analyze page load. Výsledkom sú čísla od 0 do 100 za Performance (rýchlosť), Accessibility (prístupnosť), Best Practices (odporúčané postupy) a SEO (nájditeľnosť vyhľadávačom).

Častá výhrada Čo znamená Oprava
Form elements do not have associated labels input nemá label <label for="..."> z cv02
Image elements do not have [alt] attributes obrázok nemá popis alt="..." z cv01
Background and foreground colors do not have a sufficient contrast ratio text má malý kontrast tmavší text alebo svetlejšie pozadie

Bezpečnosť: čo v aplikácii už je

Čo je v aplikácii Proti čomu Odkiaľ
htmlspecialchars pri každom výpise XSS: cudzí HTML alebo JavaScript vo výpise cv05
prepare a execute SQL injection cv07
kontroly v PHP, aj keď ich robí JavaScript request poslaný bez formulára cv05, cv10
zmazanie cez POST zmazanie otvorením adresy cv08
password_hash, password_verify únik hesiel z databázy cv09

Web v praxi má k tomu HTTPS a ochranu proti CSRF. HTTPS šifruje všetko medzi prehliadačom a serverom a nastavuje sa na serveri. Ochrana proti CSRF bráni tomu, aby formulár odoslala cudzia stránka. Framework ju pridáva do každého formulára.

Heslá: kde a ako sa ukladajú

Do databázy sa ukladá hash hesla: text, z ktorého sa heslo nedá vypočítať späť.

$hash = password_hash($pass, PASSWORD_DEFAULT);             // z hesla spraví hash; do table users ide $hash

if (password_verify($pass, $account['password_hash'])) {    // pri prihlásení: sedí zadané heslo s tým, čo je uložené ako hash
    // používateľ je prihlásený
}

Table users z cv09:

id name email password_hash
1 Jana jana@example.com $2y10Jn8JlMeT39Q1/…
2 Peter peter@example.com $2y10w0Zk8rQeX7uB2/…
Čo robí password_hash Prečo
ku každému heslu pridá náhodnú soľ (salt) dve rovnaké heslá majú rôzny hash
počíta zámerne pomaly skúšanie miliónov hesiel trvá útočníkovi roky

Formulár s heslom má method="post", aby heslo nebolo v adrese. Funkcie md5 a sha1 sú rýchle a slúžia na kontrolu files; na heslá je password_hash.

Heslo k databáze je v jednom file, db.php. Tento file je na serveri a v Kubeflow. Verejné repository, prompt pre AI ani screenshot ho neobsahujú.

Zásady pre heslá podľa štandardu NIST SP 800-63B z roku 2025:

Zásada Pre toho, kto web píše Pre toho, kto ho používa
dĺžka je dôležitejšia než zmes znakov dovoliť ľubovoľné znaky bez povinných veľkých písmen a číslic veta z viacerých slov namiesto Heslo123!
aspoň 15 znakov, keď je heslo jediná ochrana; aspoň 8 s druhým faktorom dovoliť heslo dlhé aspoň 64 znakov dlhé heslo a druhý faktor, ako na GitHub
heslo sa mení pri podozrení na únik zmenu vyžadovať len po úniku zmeniť heslo hneď, keď služba oznámi únik
nové heslo sa porovná so zoznamom uniknutých hesiel odmietnuť 123456 a password iné heslo pre každú službu
správca hesiel dovoliť vkladanie a automatické vyplnenie heslá si pamätá správca hesiel

Markdown

Markdown je obyčajný text so značkami, z ktorého program spraví HTML. Navrhol ho John Gruber v roku 2004. Files majú príponu .md.

Zápis Výsledok
# Nadpis nadpis h1; ## Nadpis je h2
**tučné** tučný text
*kurzíva* kurzíva
- položka položka zoznamu
`kód` kód v riadku
tri spätné apostrofy na riadku pred kódom a za ním blok kódu
[text](adresa) odkaz
Náhľad

Text so značkami (file .md)

# Lezecká stena

Aplikácia eviduje **lezecké cesty**.

## Stránky

- Cesty
- Nová cesta

Spustenie: `web/index.php`

[Návod 04](../navody/04-odovzdavanie.html)

Výsledok

Lezecká stena

Aplikácia eviduje lezecké cesty.

Stránky

  • Cesty
  • Nová cesta

Spustenie: web/index.php

Návod 04

Markdown je v predmete na týchto miestach:

  • README.md v každom repository; GitHub ho zobrazí ako stránku,
  • stránky tohto predmetu sú napísané v Markdown a program z nich robí HTML,
  • odpoveď, ktorú vráti chat s AI, je text v Markdown. Okno chat ho prekreslí; po skopírovaní do file sú značky ## a ** viditeľné.

JSON a webová služba

JSON je zápis údajov do textu. V Kubeflow je v ňom napísaný file sftp.json, podľa ktorého rozšírenie SFTP vie, kam posielať files:

.vscode/sftp.json
{
    "name": "sigma",
    "host": "sigma.tuke.sk",
    "protocol": "sftp",
    "port": 22,
    "username": "jn123ab",
    "privateKeyPath": "/home/jovyan/.ssh/id_ed11111",
    "remotePath": "/home/jn123ab/public_html",
    "uploadOnSave": true,
    "useTempFile": false,
    "openSsh": false,
    "ignore": [".vscode", ".git", "**/.git/**", ".DS_Store"]
}

Údaje v ukážke sú vymyslené. Zápis je ten istý, aký majú objekty v cv10 (JavaScript): { } je objekt, "key": value jedna dvojica, text je v úvodzovkách ", čísla a true alebo false sú bez úvodzoviek, [ ] je zoznam hodnôt.

V JSON posielajú údaje aj webové služby. Webová služba je adresa na cudzom serveri, ktorá vráti údaje. Služba Open-Meteo vracia predpoveď počasia; na nekomerčné použitie je bezplatná a funguje bez registrácie. Táto adresa vráti aktuálne počasie v Košiciach:

https://api.open-meteo.com/v1/forecast?latitude=48.72&longitude=21.26&current=temperature_2m,wind_speed_10m&timezone=auto

Skrátená ukážka odpovede:

{
  "latitude": 48.72,
  "longitude": 21.26,
  "timezone": "Europe/Bratislava",
  "current": {
    "time": "2026-11-24T09:15",
    "temperature_2m": 3.4,
    "wind_speed_10m": 12.2
  }
}

V content file stránky:

<button type="button" class="btn btn-outline-primary" id="weather-button">Počasie v Košiciach</button>
<p id="weather-text"></p>                          <!-- prázdny odsek, text doň zapíše JavaScript -->
web/js/app.js
const weatherButton = document.querySelector('#weather-button');     // button
const weatherText = document.querySelector('#weather-text');         // odsek na výsledok
const address = 'https://api.open-meteo.com/v1/forecast?latitude=48.72&longitude=21.26&current=temperature_2m,wind_speed_10m&timezone=auto';

if (weatherButton) {                                                 // len na stránke, kde button je
  weatherButton.addEventListener('click', function () {              // po kliknutí
    fetch(address)                                                   // pošli request na adresu služby; stránka sa neobnoví
      .then(function (response) {                                    // then: keď response príde, vykonaj túto function
        return response.json();                                      // text JSON preveď na objekt
      })
      .then(function (data) {                                        // objekt je v premennej data
        const temperature = data.current.temperature_2m;             // bodka ide hlbšie: data, v ňom current, v ňom temperature_2m
        const wind = data.current.wind_speed_10m;                    // data, v ňom current, v ňom wind_speed_10m
        weatherText.textContent = 'Košice: ' + temperature + ' °C, vietor ' + wind + ' km/h';
      })
      .catch(function () {                                           // catch: keď služba neodpovie
        weatherText.textContent = 'Služba neodpovedá.';
      });
  });
}
Živý náhľad, dá sa vyskúšať

Response zo služby:


Údaje o počasí: Open-Meteo.com

Pravidlo: fetch('ADRESA').then(function (response) { return response.json(); }).then(function (data) { ... }); Prvé then počká na response, druhé na údaje.

AI v editore

AI pri písaní kódu má tieto podoby: chat, dopĺňanie v editore a agent.

Podoba Ako pracuje
chat autor priloží files, dostane text a skopíruje ho do projektu
dopĺňanie v editore pri písaní sa sivým písmom ponúka pokračovanie riadku, kláves Tab ho prijme
agent má prístup k files projektu a k terminálu, files upravuje a príkazy spúšťa

Príklady nástrojov v editore sú GitHub Copilot, Cursor a Claude Code. Kubeflow je editor VS Code v prehliadači a takéto nástroje sa do VS Code pridávajú ako rozšírenia.

Chat (cvičenia) AI v editore
ako sa dostane k files autor ich priloží vidí otvorený projekt
ako sa výsledok dostane do projektu autor ho skopíruje AI zmení files priamo
spoločné pravidlá malá úloha, obmedzenia, kontrola výsledku malá úloha, obmedzenia, kontrola výsledku
navyše commit pred úlohou a prezretie každého zmeneného file

Chyby, ktoré AI robí:

  • použije function alebo class, ktorá neexistuje alebo sa volá inak,
  • použije zastaraný zápis, napríklad mysql_query namiesto PDO,
  • vynechá ochranu (htmlspecialchars, prepare), keď ju prompt nevyžaduje,
  • prepíše aj časti, ktoré prompt nespomínal.

Výsledok sa overuje takto: prečítať ho riadok po riadku, spustiť ho vo svojom webovom priestore, pozrieť Console a spustiť testy. Do aplikácie ide kód, ktorý jej autor vie vysvetliť.

Prompt neobsahuje heslá, obsah db.php so skutočnými údajmi ani osobné údaje iných ľudí.

AI môže byť aj súčasťou webu, napríklad ako pomocník, ktorý odpovedá návštevníkom. Volá sa cez webovú službu firmy, ktorá model prevádzkuje, tak ako počasie v ukážke. Táto služba vyžaduje prístupový kľúč. Kľúč je uložený v PHP na serveri, lebo JavaScript si v F12 prečíta každý návštevník.

Properties of a modern web site

Property What it means Where the application already has it
clear structure every thing is in one place and can be found the page file, template.php, the content file, css/style.css, js/app.js
accessibility the site can also be used by a person who sees poorly, works without a mouse or is in a place with unsuitable lighting label for inputs, alt for images, Bootstrap
security input from the user is processed as text and passwords are stored as a hash htmlspecialchars, prepare, password_hash

Clear structure: how a page is put together

After the address .../web/routes.php is opened, the page file is executed, it includes template.php and the template inserts the content file:

…/web/routes.php
routes.php page file: includes db.php, sets $title, $active, $content
template.php frame: <head> with $title, the menu highlighted by $active, <h1>, footer, js/app.js
content/routes.php content: SELECT and the listing

Every layer has its own file and its own job:

Layer Job Where it is
HTML the content and its meaning content files, template.php
CSS the look Bootstrap and css/style.css
JavaScript what happens after a click or while typing js/app.js
PHP and SQL the data the page file, the content file, the database

The look is changed in CSS, the data in PHP and SQL. A change in one layer leaves the other layers unchanged.

The meaning of the tags is part of the structure too. The browser, a search engine and a screen reader find their way by them:

<header>...</header>            <!-- hlavička webu -->
<nav>...</nav>                  <!-- menu; čítačka obrazovky naň vie skočiť -->
<main>                          <!-- hlavný obsah stránky, na stránke je raz -->
  <h1>Cesty</h1>                <!-- hlavný nadpis, na stránke je raz -->
  <h2>Nové cesty</h2>           <!-- podnadpis; po h1 nasleduje h2, po h2 h3 -->
</main>
<footer>...</footer>            <!-- päta webu -->

A page built only from <div> looks the same in the browser as this one, but a screen reader finds neither the menu nor the main content in it.

A content management system (CMS)

A content management system is a ready-made application in which the content of a web site is written through forms in the browser. Whoever writes the articles works only with forms in the administration. The most widespread one is WordPress. It was released in 2003 by Matt Mullenweg and Mike Little, it is open source and it is written in PHP with a MySQL database.

In the application In a content management system
template.php a theme: a ready-made look that can be swapped
a table in the database and a content file with the listing articles and pages stored in the database
add-ENTITY.php, edit-ENTITY.php the editor in the administration
the login from cv09 accounts with roles: an editor writes, an administrator sets things up

A content management system suits a site with articles, news and pages. For records with your own tables, like the application from the labs, your own application is written.

In practice your own application is written with ready-made code by other authors:

In the application How it is done in practice What it is
template.php and content files Laravel, Symfony a framework for PHP: ready-made page assembly, login, form checks
SQL through PDO Eloquent, Doctrine an ORM: a record from a table is an object in PHP and a library writes the SQL
Bootstrap Bootstrap, Tailwind ready-made classes for the look
js/app.js Vue, React libraries that change the elements of the page according to the data

All of them are open source: their code is public and using them is free of charge.

Accessibility: the WCAG standard

WCAG (Web Content Accessibility Guidelines) is the standard that says what a web site must meet so that everyone can use it. It is published by the W3C consortium, which also publishes the HTML and CSS standards. The current version is 2.2. It has the levels A, AA and AAA. Level AA is the one usually required.

In Slovakia accessibility is mandatory:

For whom Regulation What it requires
web sites of public administration Act No. 95/2019 Coll. and Decree No. 78/2020 Coll. WCAG 2.1, levels A and AA
e-shops and other consumer services, for example financial and transport services Act No. 351/2022 Coll., in force since 28 June 2025 an accessible web site and mobile application; microenterprises with fewer than 10 employees have an exemption

Colours and contrast

Contrast is the ratio of the brightness of the text and of the background. Black on white has the ratio 21 : 1, two identical colours 1 : 1.

What Minimum contrast for level AA
normal text 4.5 : 1
large text: from 24 px, or bold from 18.5 px 3 : 1
icons and borders of inputs 3 : 1

Text of 16 px in different colours on a white background:

Preview
Ukážkový text na bielom pozadí#21252915,43 : 1passes
Ukážkový text na bielom pozadí#6c757d4,69 : 1barely passes
Ukážkový text na bielom pozadí#adb5bd2,07 : 1fails
Ukážkový text na bielom pozadí#ffc1071,63 : 1fails

The rule about colour: information on the page is always given as text as well. A person who cannot tell red from green does not see a red border.

<!-- zle: chybu oznamuje len červený rámik -->
<input class="form-control is-invalid" name="email">

<!-- dobre: rámik a k nemu text, ktorý povie, čo je zle -->
<input class="form-control is-invalid" name="email">
<div class="invalid-feedback">E-mail nemá správny tvar.</div>

The browser shows the contrast: F12, the Elements tab, click the element with the text and in the right part of the panel click the colour square next to color. The ratio appears with a mark saying whether it passes.

Principles of web design

Principle What it means In the application with Bootstrap
hierarchy one h1, below it h2, then h3 <h1> with $title in template.php
grid the content is aligned in columns container, row, col-md-6
white space there is a gap between the parts of the page mb-3, g-3, py-4
line length 45 to 75 characters; a longer line is hard to read text in col-lg-8
typeface two typefaces at most, body text at least 16 px the default Bootstrap typeface
consistency the same action looks the same on every page btn-primary the main action, btn-outline-secondary back, btn-outline-danger delete
colours one main colour, one for warnings, the rest grey the Bootstrap colours
mobile first the page is designed for a narrow screen and extended for a wide one col-md-, navbar-expand-md
links the text of a link says where it leads “detail cesty” (route detail) instead of “click here”
forms a label above every input, a message next to the input, required inputs marked with text form-label, invalid-feedback

The same form without the principles and following them:

Preview

Wrong

OK

Right

E-mail nemá správny tvar, chýba časť za znakom @.

Odoslať prihlášku

On the left the label is missing, the text has a contrast of 2.07 : 1, the error is announced only by the colour of the border and the button does not say what it does.

Checking: Lighthouse

Lighthouse is a tool in the Chrome browser that rates a page. The procedure: open the application in your web space on sigma.tuke.sk, press F12, choose Lighthouse in the row of tabs (it may be hidden under ») and click the button Analyze page load. The result is numbers from 0 to 100 for Performance, Accessibility, Best Practices and SEO (how well search engines can find the page).

A common complaint What it means Fix
Form elements do not have associated labels an input has no label <label for="..."> from cv02
Image elements do not have [alt] attributes an image has no description alt="..." from cv01
Background and foreground colors do not have a sufficient contrast ratio the text has low contrast a darker text or a lighter background

Security: what the application already has

What is in the application Against what From where
htmlspecialchars at every output XSS: someone else’s HTML or JavaScript in the output cv05
prepare and execute SQL injection cv07
checks in PHP even when JavaScript does them a request sent without the form cv05, cv10
deleting through POST deleting by opening an address cv08
password_hash, password_verify a leak of passwords from the database cv09

A web site in practice adds HTTPS and protection against CSRF. HTTPS encrypts everything between the browser and the server and is set up on the server. Protection against CSRF prevents another page from submitting a form. A framework adds it to every form.

Passwords: where and how they are stored

The database stores a hash of the password: a text from which the password cannot be computed back.

$hash = password_hash($pass, PASSWORD_DEFAULT);             // z hesla spraví hash; do table users ide $hash

if (password_verify($pass, $account['password_hash'])) {    // pri prihlásení: sedí zadané heslo s tým, čo je uložené ako hash
    // používateľ je prihlásený
}

The table users from cv09:

id name email password_hash
1 Jana jana@example.com $2y10Jn8JlMeT39Q1/…
2 Peter peter@example.com $2y10w0Zk8rQeX7uB2/…
What password_hash does Why
it adds a random salt to every password two identical passwords have different hashes
it computes slowly on purpose trying millions of passwords takes an attacker years

A form with a password has method="post" so that the password is not in the address. The functions md5 and sha1 are fast and serve for checking files; for passwords there is password_hash.

The password to the database is in one file, db.php. This file stays out of a public repository, out of a prompt for AI and out of screenshots.

Principles for passwords according to the standard NIST SP 800-63B from 2025:

Principle For the one who writes the site For the one who uses it
length matters more than a mixture of characters allow any characters without mandatory capitals and digits a sentence of several words instead of Heslo123!
at least 15 characters when the password is the only protection; at least 8 with a second factor allow a password at least 64 characters long a long password and a second factor, as on GitHub
a password is changed when a leak is suspected require a change only after a leak change the password as soon as the service announces a leak
a new password is compared with a list of leaked passwords reject 123456 and password a different password for every service
a password manager allow pasting and autofill a password manager remembers the passwords

Markdown

Markdown is plain text with marks from which a program makes HTML. It was designed by John Gruber in 2004. The files have the extension .md.

Notation Result
# Heading an h1 heading; ## Heading is h2
**bold** bold text
*italics* italics
- item a list item
`code` code in a line
three backticks on the line before the code and after it a block of code
[text](address) a link
Preview

Text with marks (.md file)

# Lezecká stena

Aplikácia eviduje **lezecké cesty**.

## Stránky

- Cesty
- Nová cesta

Spustenie: `web/index.php`

[Návod 04](../navody/04-odovzdavanie.html)

Result

Lezecká stena

Aplikácia eviduje lezecké cesty.

Stránky

  • Cesty
  • Nová cesta

Spustenie: web/index.php

Návod 04

In this course Markdown is in these places:

  • README.md in every repository; GitHub displays it as a page,
  • the pages of this course are written in Markdown and a program makes HTML from them,
  • the answer of an AI chat is text in Markdown. The chat application renders it; after copying into a file the marks ## and ** are visible.

JSON and a web service

JSON is a notation for data as text. In Kubeflow the file sftp.json is written in it; the SFTP extension learns from it where to send the files:

.vscode/sftp.json
{
    "name": "sigma",
    "host": "sigma.tuke.sk",
    "protocol": "sftp",
    "port": 22,
    "username": "jn123ab",
    "privateKeyPath": "/home/jovyan/.ssh/id_ed11111",
    "remotePath": "/home/jn123ab/public_html",
    "uploadOnSave": true,
    "useTempFile": false,
    "openSsh": false,
    "ignore": [".vscode", ".git", "**/.git/**", ".DS_Store"]
}

The data in the example is made up. The notation is the same as for objects in JavaScript in cv10: { } is an object, "key": value one pair, text is in double quotes ", numbers and true or false are without quotes, [ ] is a list of values.

Web services send data in JSON too. A web service is an address on someone else’s server that returns data. The Open-Meteo service returns a weather forecast; it is free for non-commercial use and works without registration. This address returns the current weather in Košice:

https://api.open-meteo.com/v1/forecast?latitude=48.72&longitude=21.26&current=temperature_2m,wind_speed_10m&timezone=auto

A shortened sample of the response:

{
  "latitude": 48.72,
  "longitude": 21.26,
  "timezone": "Europe/Bratislava",
  "current": {
    "time": "2026-11-24T09:15",
    "temperature_2m": 3.4,
    "wind_speed_10m": 12.2
  }
}

In the content file of the page:

<button type="button" class="btn btn-outline-primary" id="weather-button">Počasie v Košiciach</button>
<p id="weather-text"></p>                          <!-- prázdny odsek, text doň zapíše JavaScript -->
web/js/app.js
const weatherButton = document.querySelector('#weather-button');     // button
const weatherText = document.querySelector('#weather-text');         // odsek na výsledok
const address = 'https://api.open-meteo.com/v1/forecast?latitude=48.72&longitude=21.26&current=temperature_2m,wind_speed_10m&timezone=auto';

if (weatherButton) {                                                 // len na stránke, kde button je
  weatherButton.addEventListener('click', function () {              // po kliknutí
    fetch(address)                                                   // pošli request na adresu služby; stránka sa neobnoví
      .then(function (response) {                                    // then: keď response príde, vykonaj túto function
        return response.json();                                      // text JSON preveď na objekt
      })
      .then(function (data) {                                        // objekt je v premennej data
        const temperature = data.current.temperature_2m;             // bodka ide hlbšie: data, v ňom current, v ňom temperature_2m
        const wind = data.current.wind_speed_10m;                    // data, v ňom current, v ňom wind_speed_10m
        weatherText.textContent = 'Košice: ' + temperature + ' °C, vietor ' + wind + ' km/h';
      })
      .catch(function () {                                           // catch: keď služba neodpovie
        weatherText.textContent = 'Služba neodpovedá.';
      });
  });
}
Live preview, try it

Response from the service:


Weather data: Open-Meteo.com

Rule: fetch('ADDRESS').then(function (response) { return response.json(); }).then(function (data) { ... }); The first then waits for the response, the second one for the data.

AI in the editor

AI in writing code takes the form of a chat, completion in the editor and an agent:

Form How it works
chat the author attaches files, gets text and copies it into the project
completion in the editor while typing, a continuation of the line is offered in grey; the Tab key accepts it
agent it has access to the files of the project and to the terminal, edits the files and runs commands

Examples of tools in the editor are GitHub Copilot, Cursor and Claude Code. Kubeflow is the VS Code editor in the browser and such tools are added to VS Code as extensions.

Chat (labs) AI in the editor
how it gets to the files the author attaches them it sees the open project
how the result gets into the project the author copies it the AI changes the files directly
shared rules a small task, restrictions, checking the result a small task, restrictions, checking the result
in addition a commit before the task and a look at every changed file

Mistakes AI makes:

  • it uses a function or a class that does not exist or has another name,
  • it uses an outdated notation, for example mysql_query instead of PDO,
  • it leaves out protection (htmlspecialchars, prepare) when the prompt does not require it,
  • it rewrites parts the prompt did not mention.

The result is verified like this: read it line by line, run it in your web space, look at the Console and run the tests. The application takes code its author can explain.

Passwords, the content of db.php with real data and other people’s personal data stay out of a prompt.

AI can also be a part of a web site, for example as an assistant that answers visitors. It is called through the web service of the company that runs the model, like the weather in the example. That service requires an access key. The key is stored in PHP on the server, because every visitor can read the JavaScript in F12.

Demo skúškyExam demo

Skúška má časť A a časť B, spolu 70 bodov. Na úspešné absolvovanie treba aspoň 36 bodov.

Časť Čo sa robí Body
A zostavenie aplikácie podľa zadania; povolená je AI, stránky predmetu aj vlastný projekt 30
B otázky na aplikácii z časti A, pri stole skúšajúcej 4 × 10

Časť A: aplikácia podľa zadania

V repository je veta: „Zostav aplikáciu podľa zadania tak, ako sa aplikácia stavala na cvičeniach.” Zadanie je na papieri. Ukážkové zadanie:

Program kina

table columns
films (main entity) id, name, year, length, genre_id
genres (lookup table) id, name

genres: komédia, dráma, sci-fi

name year length (min) genres
Tichá voda 2021 98 dráma
Posledný vlak 2023 112 komédia
Hviezdny prach 2024 134 sci-fi

Aplikácia:

  • výpis filmov s filtrom podľa žánru,
  • formulár na nový record (film); hodnota z genres sa vyberá v <select>,
  • prehľad: počet filmov a priemerná dĺžka (length).

Body sú za aplikáciu, ktorá beží vo svojom webovom priestore na sigma.tuke.sk v ti/skuska/ a je v repository.

Čo aplikácia obsahuje Odkiaľ to je
tables films a genres s primary key a foreign key, údaje zo zadania cv06
pripojenie k databáze, template s Bootstrap a menu cv04, cv07
výpis main entity s názvom z lookup table cv07
filter podľa lookup table cv07
formulár na nový record: hodnota z lookup table sa vyberá v HTML elemente <select>, ktorého <option> sú načítané z databázy; pred zápisom kontrola, že je každý input vyplnený cv07
prehľad s počtom a priemerom cv07

Hotová aplikácia kino, stránka Filmy s filtrom:

…/web/films.php?genre=2
Program kinaDomovFilmyNový filmPrehľad

Filmy

Filtrovať Zrušiť filter

Filmov: 1

Tichá voda dráma

Rok: 2021, dĺžka: 98 min

Stránka Nový film po odoslaní formulára:

…/web/add-film.php
Program kinaDomovFilmyNový filmPrehľad

Nový film

Film bol pridaný.
Uložiť

Stránka Prehľad:

…/web/stats.php
Program kinaDomovFilmyNový filmPrehľad

Prehľad

Počet filmov 3
Priemerná dĺžka 114,7 min

Časť B: otázky na vlastnej aplikácii

Každá otázka má dva kroky: ukázať miesto vo vlastnom kóde a povedať alebo spraviť zmenu. Body sú za oba kroky spolu. Z každého typu je jedna otázka.

Typ Ukážková otázka pre kino
cesta údaja Do formulára je napísaný rok 2025. Ukáž po poradí každý riadok, ktorým tá hodnota prejde, kým je v table films.
predpoveď Z template.php sa zmaže riadok include $content;. Povedz, čo bude na stránke, potom sa to vyskúša.
zmena v SQL Uprav výpis tak, aby boli filmy zoradené od najdlhšieho.
zmena na dvoch miestach Pridaj kontrolu, že rok je medzi 1900 a 2026, a ukáž, kde sa hláška vypíše.

Príprava

Aplikácia z časti A sa skladá z tých istých častí ako vlastný projekt: db.php, template.php, file stránky a content file pre výpis, formulár a prehľad. Kto vie vo vlastnom projekte ukázať, kde je ktorá časť a čo robí každý riadok, je pripravený na časť A aj B.

The exam has part A and part B, 70 points together. At least 36 points are needed to pass.

Part What is done Points
A building an application according to an assignment sheet; AI, the course pages and your own project are allowed 30
B questions about the application from part A, at the examiner’s desk 4 × 10

Part A: an application according to the assignment sheet

The repository holds the sentence: “Build the application according to your assignment sheet the way the application was built in the labs.” The assignment is on paper. A sample assignment:

Program kina (cinema programme)

table columns
films (main entity) id, name, year, length, genre_id
genres (lookup table) id, name

genres: komédia, dráma, sci-fi

name year length (min) genres
Tichá voda 2021 98 dráma
Posledný vlak 2023 112 komédia
Hviezdny prach 2024 134 sci-fi

The application:

  • a listing of films with a filter by genre,
  • a form for a new record (film); the value from genres is chosen in a <select>,
  • an overview: the number of films and the average length (length).

Points are for an application that runs in your web space on sigma.tuke.sk in ti/skuska/ and is in the repository.

What the application contains Where it comes from
the tables films and genres with a primary key and a foreign key, the data from the assignment cv06
the database connection, a template with Bootstrap and a menu cv04, cv07
a listing of the main entity with the name from the lookup table cv07
a filter by the lookup table cv07
a form for a new record: the value from the lookup table is chosen in the HTML element <select> whose <option> elements are loaded from the database; before writing, a check that the inputs are filled in cv07
an overview with a count and an average cv07

The finished cinema application, the page Filmy with the filter:

…/web/films.php?genre=2
Program kinaDomovFilmyNový filmPrehľad

Filmy

Filtrovať Zrušiť filter

Filmov: 1

Tichá voda dráma

Rok: 2021, dĺžka: 98 min

The page Nový film after submitting the form:

…/web/add-film.php
Program kinaDomovFilmyNový filmPrehľad

Nový film

Film bol pridaný.
Uložiť

The page Prehľad:

…/web/stats.php
Program kinaDomovFilmyNový filmPrehľad

Prehľad

Počet filmov 3
Priemerná dĺžka 114,7 min

Part B: questions about your own application

Every question has two steps: show the place in your own code and say or make the change. Points are for both steps together. There is one question of each type.

Type A sample question for the cinema
the path of a value The year 2025 is typed into the form. Show in order every line the value passes through until it is in the table films.
prediction The line include $content; is deleted from template.php. Say what will be on the page, then it is tried.
a change in SQL Change the listing so that the films are sorted from the longest.
a change in two places Add a check that the year is between 1900 and 2026 and show where the message is printed.

Preparation

The application from part A consists of the same parts as your own project: db.php, template.php, a page file and a content file for the listing, the form and the overview. Whoever can show in their own project where each part is and what every line does is ready for part A and part B.

Pred obhajobouBefore the defence

  • python3 unify.py --check skončí bez hlásenia,
  • mapa aplikácie v README.md zodpovedá files vo web/,
  • obsah web/ je v ti/projekt/ vo svojom webovom priestore na sigma.tuke.sk,
  • každá položka menu sa otvorí a Console je bez červených hlášok,
  • pri každom file je jasné, akú má rolu a čo robí každý jeho riadok.
  • python3 unify.py --check ends without a message,
  • the map of the application in README.md matches the files in web/,
  • the content of web/ is in ti/projekt/ in your web space on sigma.tuke.sk,
  • every menu item opens and the Console has no red messages,
  • for every file it is clear what its role is and what each of its lines does.