This commit is contained in:
Samuel 2024-09-13 16:45:04 +02:00
parent 059d9d5e20
commit 4b69e73f65
23 changed files with 459 additions and 23 deletions

1
www/hit.dat Normal file
View File

@ -0,0 +1 @@
0

View File

@ -7,7 +7,7 @@
<body> <body>
<?php <?php
$file = "../../../user.dat"; $file = "../../../userM2.dat";
function addUser($newUser, $file) { function addUser($newUser, $file) {

View File

@ -1,16 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php <?php
function cleanData($data) { function cleanData($data)
{
mb_internal_encoding("UTF-8"); mb_internal_encoding("UTF-8");
if(!mb_check_encoding($data)){ if (!mb_check_encoding($data)) {
header('Location: start.php'); header('Location: start.php');
} }
@ -19,7 +13,5 @@
$data = trim($data); $data = trim($data);
$data = stripslashes($data); $data = stripslashes($data);
return $data; return $data;
} }
?> ?>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -0,0 +1,137 @@
@CHARSET "UTF-8";
* {
margin:0;
padding:0;
font-family:Verdana, Geneva, sans-serif;
}
body{
font-size: 100%;
}
p {
font-size: 0.8em;
margin-bottom: 10px;
margin-top: 5px;
margin-right: 10px;
text-align: justify;
}
/* Wrapper */
#wrapper {
width: 800px;
margin-left: auto;
margin-right:auto;
margin-top:10px;
border: 2px solid rgba(0,0,0,0.8);
}
/* End wrapper */
/* Header */
header {
text-align:center;
height: 60px;
background-image: url("../bilder/bgImg.png");
color: white;
}
header h1{
font-family: Arial;
font-size: 1.9em;
padding-top: 0.25em;
}
header time{
float: right;
margin-right: 2em;
font-size: 0.8em;
}
/* End header */
nav{
border-radius: 5px; /* CSS3 */
border: 1px solid #999;
padding: 4px;
margin-bottom:5px;
}
nav ul {
list-style:none;
}
nav li{
margin-top: 5px;
border: 1px solid #000;
}
nav li a{
display:block;
font-size: 0.8em;
text-decoration: none;
color: #aa0000;
padding-left: 15px;
background-color:#FFC;
}
nav li a:hover, #leftColumn li a:active, #leftColumn li a:focus{
background-color: gray;
color: #ffffff;
}
aside {
-moz-border-radius: 5px; /* Ger rundade hörn i Firefox */
border-radius: 5px; /* CSS3 */
border: 1px solid #999;
padding: 4px;
margin-bottom:5px;
}
aside p {
font-size: 0.8em;
}
/* leftColumn */
#leftColumn {
float: left;
width: 180px;
margin: 8px;
}
#leftColumn h1 {
font-family:Arial, Helvetica, sans-serif;
font-size: 0.9em;
}
/* End leftColumn */
/* Main */
main {
margin-top: 8px;
margin-left:200px;
}
main h1{
font-family: Arial, Helvetica, sans-serif;
font-size: 1.4em;
}
main h2{
font-family: Arial, Helvetica, sans-serif;
font-size: 1.1em;
}
main section{
float:right;
width: 99%;
}
form label,a{
font-size: 0.8em;
}
/* End content */
/* Footer */
footer {
height: 30px;
background-image: url("../bilder/bgImg.png");
color: white;
font-size: 0.75em;
clear:both;
}
footer #footerRight{
float:right;
padding: 5px;
}
footer #footerLeft{
float:left;
padding: 5px;
}
/* End footer */

View File

@ -0,0 +1,41 @@
<?php
$file = "../../../userM3.dat";
function addUser($newUser, $file) {
if(file_exists($file)){
$users = unserialize(file_get_contents($file));
}else{
echo "Filen finns inte!!!";
exit;
}
if (!is_array($users)) {
$users = [];
} else {
// If file does not exist, initialize as an empty array
$users = [];
}
$users[] = $newUser;
file_put_contents($file, serialize($users));
}
function readUser($file, $användarnamn, $lösenord) {
if(file_exists($file)){
$users = unserialize(file_get_contents($file));
}else{
// Filen finns ej!! Kör om programmet “personWrite.php”
}
header('Content-Type: text/html; charset=utf-8');
foreach($users as $user) {
if ($user->getAnvändarnamn() == $användarnamn && $user->getLösenord() == $lösenord) {
echo('Välkommen ' . $user->getFörnamn() . " " . $user->getEfternamn());
break;
}
}
}
?>
</body>
</html>

View File

@ -0,0 +1,11 @@
<?php
$hit = 0;
if(file_exists("../../../hit.dat")){
$hit = file_get_contents("../../../hit.dat");
}
$hit++;
file_put_contents("../../../hit.dat",$hit);
echo "Antal användare: " . $hit;
?>

View File

@ -0,0 +1,17 @@
<?php
function cleanData($data)
{
mb_internal_encoding("UTF-8");
if (!mb_check_encoding($data)) {
header('Location: start.php');
}
$data = strip_tags($data);
$data = htmlspecialchars($data);
$data = trim($data);
$data = stripslashes($data);
return $data;
}
?>

View File

@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FeetBook</title>
</head>
<body>
<h1>FeetBook</h1>
<form action="" method="post">
<fieldset>
<legend>Sign up</legend>
<input type="hidden" name="form_id" value="sign_up">
<label>Skriv förnamn</label>
<input type="text" name="förnamn">
<label>Skriv efternamn</label>
<input type="text" name="efternamn">
<label>Skriv användarnamn</label>
<input type="text" name="användarnamn">
<label>Skriv lösenord</label>
<input type="text" name="lösenord">
<input type="submit" value="Sign Up">
</fieldset>
</form>
<form action="" method="post">
<fieldset>
<legend>Sign in</legend>
<input type="hidden" name="form_id" value="sign_in">
<label>Skriv användarnamn</label>
<input type="text" name="användarnamn">
<label>Skriv lösenord</label>
<input type="text" name="lösenord">
<input type="submit" value="Sign in">
</fieldset>
</form>
<?php
include('cleanData.php');
include('user.php');
include('addUser.php');
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['form_id'] === 'sign_up') {
$förnamn = cleandata($_POST['förnamn']);
$användarnamn = cleandata($_POST['användarnamn']);
$lösenord = cleandata($_POST['lösenord']);
$efternamn = cleandata($_POST['efternamn']);
$newUser = new user($förnamn, $efternamn, $användarnamn, $lösenord);
addUser($newUser, $file);
}
if ($_POST['form_id'] === 'sign_in') {
$användarnamn = cleandata($_POST['användarnamn']);
$lösenord = cleandata($_POST['lösenord']);
readUser($file, $användarnamn, $lösenord);
}
}
include("../../footer.html");
?>
</body>
</html>

View File

@ -0,0 +1,32 @@
<?php
session_start();
if(isset($_POST['password'],$_POST['username'])){
if($_POST['password'] == '12345' && $_POST['username']=='admin'){
$_SESSION['inloggad'] = true; // Användaren har anget rätt uppgifter.
$_SESSION['user'] = $_POST['username'];
}
}
// Om lyckad inloggning gå till index.php. Annars gå vidare och visa formuläret.
if(isset($_SESSION['inloggad'])){
header("Location: ../index.php");
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="utf-8" >
<title>Sessioner</title>
</head>
<body>
<form method="post" >
Username: <input type="text" name="username" size="20" /><br />
Password: <input type="password" name="password" size="20" /><br />
<input type="submit" value="Logga in" name="login"/>
</form>
</body>
</html>

View File

@ -0,0 +1,8 @@
<?php
session_start();
$_SESSION = array(); // Tömmer sessionsarrayen
session_destroy();
header("Location: index.php");
?>

View File

@ -0,0 +1,36 @@
<?php
class user {
private $förnamn;
private $efternamn;
private $användarnamn;
private $lösenord;
public function __construct($förnamn, $efternamn, $användarnamn, $lösenord) {
$this->förnamn = $förnamn;
$this->efternamn = $efternamn;
$this->användarnamn = $användarnamn;
$this->lösenord = $lösenord;
}
public function getFörnamn() {
return $this->förnamn;
}
public function getEfternamn() {
return $this->efternamn;
}
public function getAnvändarnamn() {
return $this->användarnamn;
}
public function getLösenord() {
return $this->lösenord;
}
public function setLösenord($lösenord) {
$this->lösenord = $lösenord;
}
}
?>

View File

@ -0,0 +1,8 @@
<aside>
<h1>Namn</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla tristique elementum nisl, et vehicula neque laoreet ut.
Praesent sed ultrices purus.
</p>
</aside>

View File

@ -0,0 +1,4 @@
<footer>
<span id="footerLeft">© Sidlayoutarna</span>
<span id="footerRight"><a href="mailto:xxx@doman">xxx@doman</a></span>
</footer>

View File

@ -0,0 +1,3 @@
<header>
<h1>Webbserverprogrammering 1 med Bygren</h1>
</header>

View File

@ -0,0 +1,9 @@
<nav>
<h1>Innehåll</h1>
<ul>
<li><a href="index.php">Hem</a></li>
<li><a href="index.php?page=blogg">Blogg</a></li>
<li><a href="index.php?page=bilder">Bilder</a></li>
<li><a href="index.php?page=kontakt">Kontakt</a></li>
</ul>
</nav>

View File

@ -0,0 +1,53 @@
<?php
session_start();
?>
<!doctype html>
<html lang="sv">
<head>
<meta charset="utf-8">
<title>Länka in sidor med PHP</title>
<link href="css/styleSheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<?php
include("inc/header.php");
?>
<section id="leftColumn">
<?php
include("inc/meny.php");
include("inc/aside.php");
?>
</section>
<!-- End leftColumn -->
<?php
$page = "start";
if (isset($_GET['page']))
$page = $_GET['page'];
switch ($page) {
case 'blogg':
include('pages/blogg.php');
break;
case 'bilder':
include('pages/bilder.php');
break;
case 'kontakt':
include('pages/kontakt.php');
break;
default:
include('pages/start.php');
}
include("inc/footer.php");
include("dataBas/besökRäknare.php");
?>
</div>
<!-- End wrapper -->
</body>
</html>

View File

@ -0,0 +1,2 @@
<p>Bild 1</p>
<p>Bild 2</p>

View File

@ -0,0 +1,13 @@
<main role="main">
<section>
<hgroup>
<h1>Min blogg Nu</h1>
<h2>I dag gör vi mallar</h2>
</hgroup>
<p>Lorem ipsum id duo autem qualisque, cu laoreet eleifend cum. Eu sea
vidit altera civibus, harum deserunt argumentum ne vim. Eu paulo
corpora appareat pro, brute everti iuvaret ne vis. Diam incorrupte
voluptatibus cu vel, nam congue soluta praesent at.
</p>
</section>
</main>

View File

@ -0,0 +1,2 @@
<p>TelefonNummber: 112</p>
<p>Get help today call your mother</p>

View File

@ -0,0 +1,3 @@
<h1>Välkommen till Webbserverprogrammering 1</h1>
<h2>Moment 2</h2>
<p>Vi kommer använda include() för att länka in sidor i vår mall.</p>

View File

@ -9,5 +9,6 @@
<a href="Moment-0/index.php">Moment-0</a> <a href="Moment-0/index.php">Moment-0</a>
<a href="Moment-1/index.php">Moment-1</a> <a href="Moment-1/index.php">Moment-1</a>
<a href="Moment-2/index.php">Moment-2</a> <a href="Moment-2/index.php">Moment-2</a>
<a href="Moment-3/index.php">Moment-3</a>
</body> </body>
</html> </html>