Differences

This shows you the differences between two versions of the page.

Link to this comparison view

lab4_code [2016-11-30 22:38]
Joakim Forsgren
lab4_code [2017-09-01 14:54]
Line 1: Line 1:
-====== Kod till Lab4 ====== 
-Ett exempel på hur man skulle kunna göra lab 4, viktigt att ni fattar vad ni gör. 
- 
-Minst 3 olika filer, en som sköter inloggning och en som sköter utloggning och den 3:e som är själva sidan.  
- 
-=== Inloggning (do_login.php) === 
-<php> 
-highlight_file('../../code/do_login.php'); 
-</php> 
- 
-=== Utloggning (do_logout.php) === 
-<php> 
-highlight_file('../../code/do_logout.php'); 
-</php> 
- 
-<code php> 
-<?php 
-include_once 'setup.php'; 
- 
-// Om man har prövat att logga in. 
-if (!empty($_POST['email']) && !empty($_POST['password'])) { 
-  // Kollar EMail och Password, bör bara finnas en... 
-  $query = "SELECT * FROM  Users WHERE EMail = '" . trim($_POST['email']) . "' AND Password = SHA1('" . trim($_POST['password']) . "')"; 
-  $result = mysqli_query($link, $query); 
-  if (mysqli_num_rows($result) != 1) { 
-    header('location: index.php'); 
-    exit(); 
-  } 
-  // Nu har vi en OK inloggning! 
-  // Sätter alla session variabler och går till sidan start.php. 
-  $row = mysqli_fetch_assoc($result); 
-  $_SESSION['UserID'] = $row['UserID']; 
-  $_SESSION['FirstName'] = $row['FirstName']; 
-  $_SESSION['LastName'] = $row['LastName']; 
-  header('location: start.php'); 
-  exit(); 
-} 
- 
-</code> 
- 
- 
-=== Själva sidan (lab4.php) === 
-<php> 
-highlight_file('../../code/lab4.php'); 
-</php>