diff --git a/Lekcja_02/index.php b/Lekcja_02/index.php index 9708680..c5f69b6 100644 --- a/Lekcja_02/index.php +++ b/Lekcja_02/index.php @@ -10,6 +10,9 @@ padding: 0; box-sizing: border-box; } + table { + border-collapse: collapse; + } th { border-right: 1px solid black; border-bottom: 1px solid black; diff --git a/Lekcja_03/codeshare.txt b/Lekcja_03/codeshare.txt new file mode 100644 index 0000000..f6e3cc1 --- /dev/null +++ b/Lekcja_03/codeshare.txt @@ -0,0 +1,86 @@ +-- sesja_on.php -- +
+ ["Francuz", "Wiolinowy"],
+ [1, "dsd"],
+ 1.22
+];
+print_r($arr);
+// $_POST['klucz']
+echo $arr['klucz'][1];
+*/
+/*
+$arr = array(
+ array(
+ "klucz" => "test"
+ ),
+ 12
+);
+print_r($arr);
+*/
+
+$imie = "Maciej";
+/*
+function test(int $a, $b = 12)
+{
+ global $imie;
+ echo $a . " " . $b;
+ echo $imie;
+ $imie = "Szymek";
+ // return
+}
+test(10);
+echo $imie;
+*/
+
+/*
+function test2(string &$i) // wskaźnik
+{
+ $i = "Fred";
+}
+test2($imie);
+echo $imie;
+*/
+session_start();
+echo session_id();
+$_SESSION['logged'] = true;
+$_SESSION['nick'] = "Scalak";
+print_r($_SESSION);
+var_dump($_SESSION);
+
+
+-- sesja_chron.php --
+ f oisehf[08esyr9euc0qsrg])
+sól salt
+dukvhjn[oe8yw[586uwfj350[tfjfj]]]xxxpa
+cikvhjn[oe8yw[586uwfj350[tfjfj]]]xxxpa
+tablice tęczowe
+*/
+
+$hash = password_hash("rasmuslerdorf", PASSWORD_BCRYPT);
+echo $hash;
+// $2y$10$s1If37c5eLHgYS68wcXEteZxSdmf4ZB0knpdWQaDMedyTEYM7zpXi
+
+if (password_verify('rasmuslerdorf', $hash)) {
+ echo 'Password is valid!';
+} else {
+ echo 'Invalid password.';
+}
diff --git a/Lekcja_03/projekt_logowanie/config.php b/Lekcja_03/projekt_logowanie/config.php
new file mode 100644
index 0000000..23b3687
--- /dev/null
+++ b/Lekcja_03/projekt_logowanie/config.php
@@ -0,0 +1,11 @@
+
diff --git a/Lekcja_03/projekt_logowanie/gen_password.php b/Lekcja_03/projekt_logowanie/gen_password.php
new file mode 100644
index 0000000..cd3ec84
--- /dev/null
+++ b/Lekcja_03/projekt_logowanie/gen_password.php
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/Lekcja_03/projekt_logowanie/index.php b/Lekcja_03/projekt_logowanie/index.php
new file mode 100644
index 0000000..122a72f
--- /dev/null
+++ b/Lekcja_03/projekt_logowanie/index.php
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+ Projekt
+
+
+
+
+ SIEMANDEROOO
+ Jesteś zalogowany jako = $_SESSION['username'] ?>.
+
+ = 1) {
+ echo 'Przeglądaj treści...';
+ }
+ if($_SESSION['user_rights_level'] >= 2) {
+ echo '
Dodaj treści...';
+ }
+ if($_SESSION['user_rights_level'] >= 3) {
+ echo '
Modyfikuj/usuń treści...';
+ }
+ ?>
+
+
Wyloguj
+
+
+
diff --git a/Lekcja_03/projekt_logowanie/login.php b/Lekcja_03/projekt_logowanie/login.php
new file mode 100644
index 0000000..110f029
--- /dev/null
+++ b/Lekcja_03/projekt_logowanie/login.php
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
+ Projekt
+
+
+
+
+
+
+
diff --git a/Lekcja_03/projekt_logowanie/logout.php b/Lekcja_03/projekt_logowanie/logout.php
new file mode 100644
index 0000000..7d71fa8
--- /dev/null
+++ b/Lekcja_03/projekt_logowanie/logout.php
@@ -0,0 +1,6 @@
+
\ No newline at end of file
diff --git a/Lekcja_03/projekt_logowanie/validate.php b/Lekcja_03/projekt_logowanie/validate.php
new file mode 100644
index 0000000..2f20d30
--- /dev/null
+++ b/Lekcja_03/projekt_logowanie/validate.php
@@ -0,0 +1,38 @@
+prepare("SELECT * FROM uzytkownicy WHERE username = ?;");
+ $stmt->bind_param("s", $_POST["username"]);
+ $stmt->execute();
+
+ $result = $stmt->get_result();
+
+ if($result->num_rows < 1) {
+ header("Location: ./login.php?error=true");
+ exit();
+ }
+
+ $cred = $result->fetch_assoc();
+
+ if(password_verify($_POST['password'], $cred['password_hash'])) {
+ $_SESSION['username'] = $cred['username'];
+ $_SESSION['user_id'] = $cred['id'];
+ $_SESSION['user_rights_level'] = $cred['rights_level'];
+ $_SESSION['logged'] = true;
+
+ header("Location: ./");
+ exit();
+ } else {
+ header("Location: ./login.php?error=true");
+ exit();
+ }
+
+?>
diff --git a/Lekcja_03/referencje.md b/Lekcja_03/referencje.md
new file mode 100644
index 0000000..f53be7d
--- /dev/null
+++ b/Lekcja_03/referencje.md
@@ -0,0 +1,29 @@
+# Referencje
+
+Domyślnym zachowaniem funkcji jest skopiowanie wartości argumentu do nowej zmiennej uzywanej w funkcji.
+
+```php
+$zmienna = "wartosc1";
+
+function test($argument) { // argument przekazany funkcji
+ $argument = "wartosc2"; // zmieniamy wartość argumentu w funkcji
+ echo $argument; // wypisze się "wartosc2"
+}
+
+test($zmienna);
+echo $zmienna; // ALE! Jako że zmieniliśmy argument w funkcji, mimo że pochodzi on od zmiennej $zmienna, oryginalna zmienna pozostaje taka sama. Wypisane zostanie "wartosc1"
+```
+
+Możemy jednak zamiast tego przekazać do funkcji jedynie WSKAZANIE, gdzie znajduje się oryginalna zmienna. Wtedy wartość nie jest kopiowana i pracujemy na oryginale.
+
+```php
+$zmienna = "wartosc1";
+
+function test(&$argument) { // odniesienie do argumentu przekazane funkcji
+ $argument = "wartosc2"; // zmieniamy wartość argumentu, a co za tym idzie wartość oryginalnej zmiennej
+ echo $argument; // wypisze się "wartosc2"
+}
+
+test($zmienna);
+echo $zmienna; // tutaj też "wartosc2"
+```
diff --git a/Lekcja_03/sesja_chron.php b/Lekcja_03/sesja_chron.php
new file mode 100644
index 0000000..a42f4d0
--- /dev/null
+++ b/Lekcja_03/sesja_chron.php
@@ -0,0 +1,10 @@
+
\ No newline at end of file
diff --git a/Lekcja_03/sesja_off.php b/Lekcja_03/sesja_off.php
new file mode 100644
index 0000000..c4c69fe
--- /dev/null
+++ b/Lekcja_03/sesja_off.php
@@ -0,0 +1,4 @@
+
\ No newline at end of file
diff --git a/Lekcja_03/sesja_on.php b/Lekcja_03/sesja_on.php
new file mode 100644
index 0000000..4949b8d
--- /dev/null
+++ b/Lekcja_03/sesja_on.php
@@ -0,0 +1,5 @@
+
\ No newline at end of file