Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
lab4_code [2015-09-10 08:49]
127.0.0.1 external edit
lab4_code [2016-11-30 22:38]
Joakim Forsgren
Line 13: Line 13:
 highlight_file('../../code/do_logout.php'); highlight_file('../../code/do_logout.php');
 </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>