diff --git a/www/public/M6/01/index.php b/www/public/M6/01/index.php new file mode 100644 index 0000000..a9156f0 --- /dev/null +++ b/www/public/M6/01/index.php @@ -0,0 +1,25 @@ + + + + + + M6 | 01 + + +prepare("SELECT Name, Population FROM country WHERE Name LIKE 'Z%' ORDER BY Population DESC"); + $stmt->execute(); + + $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach( $result as $row ){ + echo "Country: ".$row['Name']; + echo " Population: ".$row['Population']; + echo "

"; + } +?> + + \ No newline at end of file diff --git a/www/public/M6/02/index.php b/www/public/M6/02/index.php new file mode 100644 index 0000000..47cee25 --- /dev/null +++ b/www/public/M6/02/index.php @@ -0,0 +1,35 @@ + + + + + + M6 | 01 + + +
+ + + +

+
+ + prepare("SELECT Name, Population FROM city WHERE Name LIKE :city ORDER BY Name"); + $stmt->bindValue(":city", "$city%", PDO::PARAM_STR); + $stmt->execute(); + + $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach( $result as $row ){ + echo "City: ".$row['Name']; + echo " Population: ".$row['Population']; + echo "

"; + } + ?> + + \ No newline at end of file diff --git a/www/public/M6/03/index.php b/www/public/M6/03/index.php new file mode 100644 index 0000000..012e5ba --- /dev/null +++ b/www/public/M6/03/index.php @@ -0,0 +1,48 @@ + + + + + + M6 | 01 + + +
+ +

+ +

+ +

+ +

+ +

+
+ + prepare("INSERT INTO user(uid, firstname, surname, username, password) VALUES(UUID(), :fn, :sn,:user,:pwd)"); + + $stmt->bindValue(":fn", $firstName); + $stmt->bindValue(":sn", $surName); + $stmt->bindValue(":user", $username); + $stmt->bindValue(":pwd", $password); + + try{ + $stmt->execute(); + echo "Good"; + }catch(Exception $e){ + echo "Not good"; + } + } + ?> + + \ No newline at end of file diff --git a/www/public/M6/04/index.php b/www/public/M6/04/index.php new file mode 100644 index 0000000..406e557 --- /dev/null +++ b/www/public/M6/04/index.php @@ -0,0 +1,18 @@ + + + + + + M6 | 04 + + + Good"; + else echo "

No good

"; + ?> + Log In + + \ No newline at end of file diff --git a/www/public/M6/04/login.php b/www/public/M6/04/login.php new file mode 100644 index 0000000..96d7c89 --- /dev/null +++ b/www/public/M6/04/login.php @@ -0,0 +1,62 @@ + + + + + + M6 | 01 + + +
+ + +

+ +

+



+
+ +
+ + +

+ +

+ +

+ +

+



+
+ +
+ +

+
+ + prepare("INSERT INTO user(uid, firstname, surname, username, password) VALUES(UUID(), :fn, :sn,:user,:pwd)"); + + $stmt->bindValue(":fn", $firstName); + $stmt->bindValue(":sn", $surName); + $stmt->bindValue(":user", $username); + $stmt->bindValue(":pwd", $password); + + try{ + $stmt->execute(); + echo "Good"; + }catch(Exception $e){ + echo "Not good"; + } + } + ?> + + \ No newline at end of file diff --git a/www/public/M6/04/userManipulation.php b/www/public/M6/04/userManipulation.php new file mode 100644 index 0000000..c827f19 --- /dev/null +++ b/www/public/M6/04/userManipulation.php @@ -0,0 +1,81 @@ +prepare("SELECT * FROM user WHERE username = :username"); + $stmt->bindValue(":username", $username); + + $stmt->execute(); + + if ($stmt->rowCount() != 1) header("Location: login.php"); + + $user = $stmt->fetch(PDO::FETCH_ASSOC); + if (password_verify($password, $user['password'])) { + $_SESSION = array(); + session_start(); + + $_SESSION['uid'] = $user['uid']; + $_SESSION['username'] = $user['username']; + $_SESSION['name'] = $user['surname'] . " " . $user['firstname']; + + $_SESSION['logged_in'] = true; + header("Location: index.php"); + } +} +function signup() +{ + if (!isset($_POST['firstName'], $_POST['surName'], $_POST['username'], $_POST['password'])) { + header("Location: login.php"); + exit(); + } + + include_once('../inc/egytalk_connect.php'); + $firstName = filter_input(INPUT_POST, 'firstName', FILTER_SANITIZE_SPECIAL_CHARS); + $surName = filter_input(INPUT_POST, 'surName', FILTER_SANITIZE_SPECIAL_CHARS); + $username = filter_input(INPUT_POST, 'username', FILTER_UNSAFE_RAW); + $password = password_hash($_POST['password'], PASSWORD_DEFAULT); + + + $stmt = $db->prepare("INSERT INTO user(uid, firstname, surname, username, password) VALUES(UUID(), :fn, :sn,:user,:pwd)"); + + $stmt->bindValue(":fn", $firstName); + $stmt->bindValue(":sn", $surName); + $stmt->bindValue(":user", $username); + $stmt->bindValue(":pwd", $password); + + try { + $stmt->execute(); + + $_SESSION = array(); + session_start(); + + $_SESSION['logged_in'] = true; + header("Location: index.php"); + } catch (Exception $e) { + header("Location: login.php"); + exit(); + } +} + +function logout() +{ + if (session_status() == PHP_SESSION_NONE) { + session_start(); + } + $_POST = array(); + $_SESSION = array(); // Tömmer sessionsarrayen + session_regenerate_id(true); + + header("Location: index.php"); + exit(); +} diff --git a/www/public/M6/inc/egytalk_connect.php b/www/public/M6/inc/egytalk_connect.php new file mode 100644 index 0000000..a50c0fa --- /dev/null +++ b/www/public/M6/inc/egytalk_connect.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/www/public/M6/inc/world_connect.php b/www/public/M6/inc/world_connect.php new file mode 100644 index 0000000..89cbf39 --- /dev/null +++ b/www/public/M6/inc/world_connect.php @@ -0,0 +1,11 @@ + \ No newline at end of file