From 866c6b37315cd958c784ccdcc8e37f10a3528b39 Mon Sep 17 00:00:00 2001 From: vadym Novoselskyi Date: Mon, 9 Sep 2024 14:19:57 +0200 Subject: [PATCH] add m4 part 1 --- www/M3-02-hit.dat | 2 +- www/M3-03-hit.dat | 2 +- www/M3-04-hit.dat | 2 +- www/M3-04-messages.dat | 3 +- www/M3-06-hit.dat | 2 +- www/M3-06-messages.dat | 1 + www/M3-06-users.dat | Bin 255 -> 593 bytes www/M4-01-users.dat | Bin 0 -> 289 bytes www/public/M3/02/index.php | 20 +++--- www/public/M3/06/handle.php | 46 ------------- www/public/M3/06/index.php | 8 +++ www/public/M3/06/pages/klotter.php | 18 ++--- www/public/M3/06/saveMsg.php | 27 +++++--- www/public/M4/01/User.php | 28 ++++++++ www/public/M4/01/index.php | 94 ++++++++++++++++++++++++++ www/public/M4/01/login.php | 44 ++++++++++++ www/public/M4/01/userManipulation.php | 47 +++++++++++++ www/public/M4/02/User.php | 28 ++++++++ www/public/M4/02/index.php | 94 ++++++++++++++++++++++++++ www/public/M4/02/login.php | 44 ++++++++++++ www/public/M4/02/userManipulation.php | 47 +++++++++++++ 21 files changed, 474 insertions(+), 83 deletions(-) create mode 100644 www/M3-06-messages.dat create mode 100644 www/M4-01-users.dat delete mode 100644 www/public/M3/06/handle.php create mode 100644 www/public/M4/01/User.php create mode 100644 www/public/M4/01/index.php create mode 100644 www/public/M4/01/login.php create mode 100644 www/public/M4/01/userManipulation.php create mode 100644 www/public/M4/02/User.php create mode 100644 www/public/M4/02/index.php create mode 100644 www/public/M4/02/login.php create mode 100644 www/public/M4/02/userManipulation.php diff --git a/www/M3-02-hit.dat b/www/M3-02-hit.dat index 8fdd954..31ff414 100644 --- a/www/M3-02-hit.dat +++ b/www/M3-02-hit.dat @@ -1 +1 @@ -22 \ No newline at end of file +48 \ No newline at end of file diff --git a/www/M3-03-hit.dat b/www/M3-03-hit.dat index 56a6051..bf0d87a 100644 --- a/www/M3-03-hit.dat +++ b/www/M3-03-hit.dat @@ -1 +1 @@ -1 \ No newline at end of file +4 \ No newline at end of file diff --git a/www/M3-04-hit.dat b/www/M3-04-hit.dat index bf0d87a..62f9457 100644 --- a/www/M3-04-hit.dat +++ b/www/M3-04-hit.dat @@ -1 +1 @@ -4 \ No newline at end of file +6 \ No newline at end of file diff --git a/www/M3-04-messages.dat b/www/M3-04-messages.dat index 8be9d17..bece204 100644 --- a/www/M3-04-messages.dat +++ b/www/M3-04-messages.dat @@ -1 +1,2 @@ -

Från: wreqtrthsr

reywtyret


Från: eargnkdsl

earsthy


Från: aeawwtsrthd

agdhsf


Från: argsdn

hsdtrj


Från: ewttr

rerew


Från: nklhio

hiohiohio


Från: jo

jijpnin


Från:

j


Från: joqoapre

dvbilgfb

\ No newline at end of file +

Från: wreqtrthsr

reywtyret


Från: eargnkdsl

earsthy


Från: aeawwtsrthd

agdhsf


Från: argsdn

hsdtrj


Från: ewttr

rerew


Från: nklhio

hiohiohio


Från: jo

jijpnin


Från:

j


Från: joqoapre

dvbilgfb


Från: 1234

testtest +


Från:
Vadym

dfsgdhsg

\ No newline at end of file diff --git a/www/M3-06-hit.dat b/www/M3-06-hit.dat index bf0d87a..301160a 100644 --- a/www/M3-06-hit.dat +++ b/www/M3-06-hit.dat @@ -1 +1 @@ -4 \ No newline at end of file +8 \ No newline at end of file diff --git a/www/M3-06-messages.dat b/www/M3-06-messages.dat new file mode 100644 index 0000000..5e6a3fd --- /dev/null +++ b/www/M3-06-messages.dat @@ -0,0 +1 @@ +

Från: 555

afsdgfh

\ No newline at end of file diff --git a/www/M3-06-users.dat b/www/M3-06-users.dat index e81d6ca2d60328e4e31cefca718bd142aa5ca423..20dc8cae2441055940dff1aa936957f337448063 100644 GIT binary patch delta 103 zcmey*c#(x8(aPMaI@8Kv;<|u|5zCk}t&D*zAZ0RfojQl9l~S0aOQi3_+fsZ$c3EOd tWv-HSZKjp!#C2NCrlzJ7Z_9E5DX^FsPzQ^Nm6GAa8?xLW8VGDAZ7pn delta 22 dcmcb}@}H3-(aPAWI@8KvG9zQq#Hb~VwE$Fr2Pgml diff --git a/www/M4-01-users.dat b/www/M4-01-users.dat new file mode 100644 index 0000000000000000000000000000000000000000..b0f1c20ad7ffa64d1090f9853bbf61474ad6d3b6 GIT binary patch literal 289 zcma)$$qs@r6h--#hP6<{BG07*C_$72uB_B}mwRq*@=gvGyg8VY z2y8%!ECf=G1l*&hSiAM7&Z`1Vq}nJ{@i%C5DZ556)e;ksZasBu>M1?@p*Og`N-wFr zB;$T}w~PBNBahVHw!?$iNV0kyo5i3WO*!60>skNg!vX(kGX#V&{!3 lU3w-oww%c4Minm$*RRJx$+FX)O`B_aVI^%tE}p&2=Lk@ literal 0 HcmV?d00001 diff --git a/www/public/M3/02/index.php b/www/public/M3/02/index.php index af38e30..8a2ede0 100644 --- a/www/public/M3/02/index.php +++ b/www/public/M3/02/index.php @@ -2,18 +2,14 @@ if (session_status() == PHP_SESSION_NONE) { session_start(); } - else { - $_SESSION = array(); // Tömmer sessionsarrayen - session_destroy(); - } - $hit = 0; - if(file_exists("../../../M3-02-hit.dat")) { - $hit = file_get_contents("../../../M3-02-hit.dat"); - } - $hit++; // Ökar antalet besökare med 1 - - file_put_contents("../../../M3-02-hit.dat", $hit); - echo $hit; + $hit = 0; + if(file_exists("../../../M3-02-hit.dat")) { + $hit = file_get_contents("../../../M3-02-hit.dat"); + } + $hit++; // Ökar antalet besökare med 1 + + file_put_contents("../../../M3-02-hit.dat", $hit); + echo $hit; ?> diff --git a/www/public/M3/06/handle.php b/www/public/M3/06/handle.php deleted file mode 100644 index b13fb48..0000000 --- a/www/public/M3/06/handle.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - M3 06 - - - - getUsername(); - echo "
Pass: " . $user->getPassword(); - } else { - header("Location: index.php"); - exit(); - } - } - else if(isset($_POST["signup"])) { - addUser($user); - header("Location: index.php"); - exit(); - } - - - function cleanData($data) - { - $data = strip_tags($data); - $data = htmlspecialchars($data); - $data = trim($data); - $data = stripslashes($data); - return $data; - } - ?> - - - \ No newline at end of file diff --git a/www/public/M3/06/index.php b/www/public/M3/06/index.php index b5210a4..ec359ed 100644 --- a/www/public/M3/06/index.php +++ b/www/public/M3/06/index.php @@ -27,7 +27,12 @@ function login() header("Location: login.php"); exit(); } + if (session_status() == PHP_SESSION_NONE) { + session_start(); + } $_SESSION['logged_in'] = true; + $_SESSION['username'] = $username; + $_SESSION['password'] = $password; } function signup() { if (isset($_POST["username"]) && $_POST["username"] != "") $username = $_POST["username"]; @@ -40,11 +45,14 @@ function signup() { header("Location: login.php"); exit(); } + $username = cleanData($username); $user = new User($username, $password); addUser($user); incUserCount(); $_SESSION['logged_in'] = true; + $_SESSION['username'] = $username; + $_SESSION['password'] = $password; } function logout() diff --git a/www/public/M3/06/pages/klotter.php b/www/public/M3/06/pages/klotter.php index 40affd2..2d6f3ce 100644 --- a/www/public/M3/06/pages/klotter.php +++ b/www/public/M3/06/pages/klotter.php @@ -1,16 +1,11 @@ -No login "; -} -else { -?>

Klotterplanket

-
-
- + Namn
'; + echo '
'; + ?>
-
+
@@ -18,5 +13,4 @@ else { if(file_exists("../../../M3-06-messages.dat")) { echo file_get_contents("../../../M3-06-messages.dat"); } -} - ?> \ No newline at end of file +?> \ No newline at end of file diff --git a/www/public/M3/06/saveMsg.php b/www/public/M3/06/saveMsg.php index eae70fc..f14b29b 100644 --- a/www/public/M3/06/saveMsg.php +++ b/www/public/M3/06/saveMsg.php @@ -1,8 +1,19 @@ -

Från: " . $_POST['name'] . "

"; - $msg = "

" . $_POST['message'] . "

"; - - file_put_contents("../../../M3-06-messages.dat",$name.$msg,FILE_APPEND); - - header("location: index.php?page=klotter"); //Omdirigerar till klotterplanket -?> \ No newline at end of file +

Från: " . $_SESSION['username'] . "

"; + $msg = "

" . cleanData($_POST['message']) . "

"; + + file_put_contents("../../../M3-06-messages.dat", $name . $msg, FILE_APPEND); + + header("location: index.php?page=klotter"); //Omdirigerar till klotterplanket + + function cleanData($data) + { + $data = strip_tags($data); + $data = htmlspecialchars($data); + $data = trim($data); + $data = stripslashes($data); + return $data; +} diff --git a/www/public/M4/01/User.php b/www/public/M4/01/User.php new file mode 100644 index 0000000..afa0130 --- /dev/null +++ b/www/public/M4/01/User.php @@ -0,0 +1,28 @@ +username = $username; + $this->password = $password; + } + + public function getUsername() { + return $this->username; + } + + public function getPassword() { + return $this->password; + } + + public function setUsername($username) { + $this->username = $username; + } + + public function setPassword($password) { + $this->password = $password; + } +} diff --git a/www/public/M4/01/index.php b/www/public/M4/01/index.php new file mode 100644 index 0000000..ad26309 --- /dev/null +++ b/www/public/M4/01/index.php @@ -0,0 +1,94 @@ + + + + + + + M4 | 01 + + + + +
+ Logged in!"; + } + else { + echo "

Not logged in!

"; + } + ?> + Login +
+ + + \ No newline at end of file diff --git a/www/public/M4/01/login.php b/www/public/M4/01/login.php new file mode 100644 index 0000000..c367978 --- /dev/null +++ b/www/public/M4/01/login.php @@ -0,0 +1,44 @@ + + + + + + Login + + +
+
+ Login + + +

+ +

+ +
+
+ +
+
+ Signup + + +

+ +

+ +
+
+ +
+
+ +
+
+ Logout + + +
+
+ + \ No newline at end of file diff --git a/www/public/M4/01/userManipulation.php b/www/public/M4/01/userManipulation.php new file mode 100644 index 0000000..7dacf2d --- /dev/null +++ b/www/public/M4/01/userManipulation.php @@ -0,0 +1,47 @@ + + + + + + Person write + + + + + getUsername() == $user->getUsername() && password_verify($userToFind->getPassword(), $user->getPassword())) return true; + } + return false; + } + ?> + + + \ No newline at end of file diff --git a/www/public/M4/02/User.php b/www/public/M4/02/User.php new file mode 100644 index 0000000..afa0130 --- /dev/null +++ b/www/public/M4/02/User.php @@ -0,0 +1,28 @@ +username = $username; + $this->password = $password; + } + + public function getUsername() { + return $this->username; + } + + public function getPassword() { + return $this->password; + } + + public function setUsername($username) { + $this->username = $username; + } + + public function setPassword($password) { + $this->password = $password; + } +} diff --git a/www/public/M4/02/index.php b/www/public/M4/02/index.php new file mode 100644 index 0000000..ad26309 --- /dev/null +++ b/www/public/M4/02/index.php @@ -0,0 +1,94 @@ + + + + + + + M4 | 01 + + + + +
+ Logged in!"; + } + else { + echo "

Not logged in!

"; + } + ?> + Login +
+ + + \ No newline at end of file diff --git a/www/public/M4/02/login.php b/www/public/M4/02/login.php new file mode 100644 index 0000000..c367978 --- /dev/null +++ b/www/public/M4/02/login.php @@ -0,0 +1,44 @@ + + + + + + Login + + +
+
+ Login + + +

+ +

+ +
+
+ +
+
+ Signup + + +

+ +

+ +
+
+ +
+
+ +
+
+ Logout + + +
+
+ + \ No newline at end of file diff --git a/www/public/M4/02/userManipulation.php b/www/public/M4/02/userManipulation.php new file mode 100644 index 0000000..f83d150 --- /dev/null +++ b/www/public/M4/02/userManipulation.php @@ -0,0 +1,47 @@ + + + + + + Person write + + + + + getUsername() == $user->getUsername() && password_verify($userToFind->getPassword(), $user->getPassword())) return true; + } + return false; + } + ?> + + + \ No newline at end of file