add M2
This commit is contained in:
parent
546c1a36a8
commit
1a34e3e93b
BIN
www/M2-09-users.dat
Normal file
BIN
www/M2-09-users.dat
Normal file
Binary file not shown.
@ -12,23 +12,30 @@
|
||||
if(isset($_POST["username"])) $username = $_POST["username"];
|
||||
if(isset($_POST["password"])) $password = $_POST["password"];
|
||||
|
||||
$name = cleanData($name);
|
||||
$surname = cleanData($surname);
|
||||
$username = cleanData($username);
|
||||
$password = cleanData($password);
|
||||
$name = strip_tags($name);
|
||||
$name = htmlspecialchars($name);
|
||||
$name = trim($name);
|
||||
$name = stripslashes($name);
|
||||
|
||||
$surname = strip_tags($surname);
|
||||
$surname = htmlspecialchars($surname);
|
||||
$surname = trim($surname);
|
||||
$surname = stripslashes($surname);
|
||||
|
||||
$username = strip_tags($username);
|
||||
$username = htmlspecialchars($username);
|
||||
$username = trim($username);
|
||||
$username = stripslashes($username);
|
||||
|
||||
$password = strip_tags($password);
|
||||
$password = htmlspecialchars($password);
|
||||
$password = trim($password);
|
||||
$password = stripslashes($password);
|
||||
|
||||
echo "Name: " . $name . "<br>";
|
||||
echo "Surname: " . $surname . "<br>";
|
||||
echo "Username: " . $username . "<br>";
|
||||
echo "Password: " . $password . "<br>";
|
||||
|
||||
function cleanData($data) {
|
||||
$data = strip_tags($data);
|
||||
$data = htmlspecialchars($data);
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
return $data;
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
34
www/public/M2/06/handle.php
Normal file
34
www/public/M2/06/handle.php
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>M2 05</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if(isset($_POST["name"])) $name = $_POST["name"];
|
||||
if(isset($_POST["surname"])) $surname = $_POST["surname"];
|
||||
if(isset($_POST["username"])) $username = $_POST["username"];
|
||||
if(isset($_POST["password"])) $password = $_POST["password"];
|
||||
|
||||
$name = cleanData($name);
|
||||
$surname = cleanData($surname);
|
||||
$username = cleanData($username);
|
||||
$password = cleanData($password);
|
||||
|
||||
echo "Name: " . $name . "<br>";
|
||||
echo "Surname: " . $surname . "<br>";
|
||||
echo "Username: " . $username . "<br>";
|
||||
echo "Password: " . $password . "<br>";
|
||||
|
||||
function cleanData($data) {
|
||||
$data = strip_tags($data);
|
||||
$data = htmlspecialchars($data);
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
return $data;
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
24
www/public/M2/06/index.php
Normal file
24
www/public/M2/06/index.php
Normal file
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>M2 02</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="handle.php" method="post">
|
||||
<fieldset >
|
||||
<legend>Login</legend>
|
||||
<label>Your name: </label>
|
||||
<input type="text" name="name">
|
||||
<label>Your surname: </label>
|
||||
<input type="text" name="surname"> <br> <br>
|
||||
<label>Your username: </label>
|
||||
<input type="text" name="username">
|
||||
<label>Your password: </label>
|
||||
<input type="text" name="password">
|
||||
<input type="submit" value="Submit">
|
||||
</fieldset>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
55
www/public/M2/07/index.php
Normal file
55
www/public/M2/07/index.php
Normal file
@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>M2 02</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
if(isset($_POST["name"])) $name = $_POST["name"];
|
||||
if(isset($_POST["surname"])) $surname = $_POST["surname"];
|
||||
if(isset($_POST["username"])) $username = $_POST["username"];
|
||||
if(isset($_POST["password"])) $password = $_POST["password"];
|
||||
|
||||
$name = cleanData($name);
|
||||
$surname = cleanData($surname);
|
||||
$username = cleanData($username);
|
||||
$password = cleanData($password);
|
||||
|
||||
echo "Name: " . $name . "<br>";
|
||||
echo "Surname: " . $surname . "<br>";
|
||||
echo "Username: " . $username . "<br>";
|
||||
echo "Password: " . $password . "<br>";
|
||||
}
|
||||
function cleanData($data) {
|
||||
$data = strip_tags($data);
|
||||
$data = htmlspecialchars($data);
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<form action="" method="post">
|
||||
<fieldset >
|
||||
<legend>Login</legend>
|
||||
<label>Your name: </label>
|
||||
<input type="text" name="name">
|
||||
<label>Your surname: </label>
|
||||
<input type="text" name="surname"> <br> <br>
|
||||
<label>Your username: </label>
|
||||
<input type="text" name="username">
|
||||
<label>Your password: </label>
|
||||
<input type="text" name="password">
|
||||
<input type="submit" value="Submit">
|
||||
</fieldset>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -1,26 +1,15 @@
|
||||
<?php
|
||||
class Person {
|
||||
|
||||
private $name;
|
||||
private $surname;
|
||||
class User
|
||||
{
|
||||
private $username;
|
||||
private $password;
|
||||
|
||||
public function __construct($name, $surname, $username, $password) {
|
||||
$this->name = $name;
|
||||
$this->surname = $surname;
|
||||
public function __construct($username, $password)
|
||||
{
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getSurname() {
|
||||
return $this->surname;
|
||||
}
|
||||
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
@ -29,7 +18,11 @@ class Person {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function saetUsername($username) {
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
}
|
||||
}
|
27
www/public/M2/08/handle.php
Normal file
27
www/public/M2/08/handle.php
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>M2 08</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
include("User.php");
|
||||
if(isset($_POST["username"])) $username = $_POST["username"];
|
||||
if(isset($_POST["password"])) $password = $_POST["password"];
|
||||
$username = cleanData($username);
|
||||
|
||||
$newUser = new User($username, $password);
|
||||
echo "Hello: " . $newUser->getUsername();
|
||||
|
||||
function cleanData($data) {
|
||||
$data = strip_tags($data);
|
||||
$data = htmlspecialchars($data);
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
return $data;
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
20
www/public/M2/08/index.php
Normal file
20
www/public/M2/08/index.php
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>M2 08</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="handle.php" method="post">
|
||||
<fieldset >
|
||||
<legend>Login</legend>
|
||||
<label>Your username: </label>
|
||||
<input type="text" name="username"> <br> <br>
|
||||
<label>Your password: </label>
|
||||
<input type="password" name="password"> <br> <br>
|
||||
<input type="submit" value="Submit">
|
||||
</fieldset>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
28
www/public/M2/09/User.php
Normal file
28
www/public/M2/09/User.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
class User
|
||||
{
|
||||
private $username;
|
||||
private $password;
|
||||
|
||||
public function __construct($username, $password)
|
||||
{
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function saetUsername($username) {
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
}
|
45
www/public/M2/09/handle.php
Normal file
45
www/public/M2/09/handle.php
Normal file
@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>M2 08</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
include("userManipulation.php");
|
||||
|
||||
if (isset($_POST["username"])) $username = $_POST["username"];
|
||||
if (isset($_POST["password"])) $password = $_POST["password"];
|
||||
$username = cleanData($username);
|
||||
$user = new User($username, $password);
|
||||
|
||||
if (isset($_POST["login"])) {
|
||||
if (isPresent($user)) {
|
||||
echo "User: " . $user->getUsername();
|
||||
echo "<br>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;
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
|
||||
</html>
|
39
www/public/M2/09/index.php
Normal file
39
www/public/M2/09/index.php
Normal file
@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>M2 08</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form action="handle.php" method="post">
|
||||
<fieldset>
|
||||
<legend>Login</legend>
|
||||
<input type="hidden" name="login">
|
||||
<label>Your username: </label>
|
||||
<input type="text" name="username"> <br> <br>
|
||||
<label>Your password: </label>
|
||||
<input type="password" name="password"> <br> <br>
|
||||
<input type="submit" value="Submit">
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<form action="handle.php" method="post">
|
||||
<fieldset>
|
||||
<legend>Signup</legend>
|
||||
<input type="hidden" name="signup">
|
||||
<label>Your username: </label>
|
||||
<input type="text" name="username"> <br> <br>
|
||||
<label>Your password: </label>
|
||||
<input type="password" name="password"> <br> <br>
|
||||
<input type="submit" value="Submit">
|
||||
</fieldset>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
47
www/public/M2/09/userManipulation.php
Normal file
47
www/public/M2/09/userManipulation.php
Normal file
@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="se">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Person write</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
include("User.php");
|
||||
|
||||
function addUser($user)
|
||||
{
|
||||
$file = "../../../M2-09-users.dat";
|
||||
|
||||
if(file_exists($file)) {
|
||||
$users = unserialize(file_get_contents($file));
|
||||
$users[] = $user;
|
||||
file_put_contents($file, serialize($users));
|
||||
}
|
||||
else {
|
||||
$users = array();
|
||||
$users[] = $user;
|
||||
file_put_contents($file, serialize($users));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function isPresent($userToFind)
|
||||
{
|
||||
$file = "../../../M2-09-users.dat";
|
||||
if (file_exists($file)) {
|
||||
$userArray = unserialize(file_get_contents($file));
|
||||
}
|
||||
else return false;
|
||||
|
||||
foreach($userArray as $user) {
|
||||
if($userToFind->getUsername() == $user->getUsername() && $userToFind->getPassword() == $user->getPassword()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user