index.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. # Copyright © 2017 Nichlas Severinsen
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. session_start();
  18. $config = include('config/config.php');
  19. $db = new PDO(
  20. 'mysql:host='.$config['hostname'].';dbname='.$config['database'],
  21. $config['username'],
  22. $config['password']);
  23. $is_logged_in = false;
  24. if(isset($_SESSION['username']) && isset($_SESSION['session_key'])){
  25. $sql = $db->prepare("SELECT session_key FROM user WHERE username=?");
  26. $sql->execute(array($_SESSION['username']));
  27. $row = $sql->fetch(PDO::FETCH_ASSOC);
  28. if($_SESSION['session_key'] == $row['session_key']){
  29. $is_logged_in = true;
  30. }
  31. }
  32. if(isset($_COOKIE['username']) && isset($_COOKIE['session_key'])){
  33. $sql = $db->prepare("SELECT session_key FROM user WHERE username=?");
  34. $sql->execute(array($_COOKIE['username']));
  35. $row = $sql->fetch(PDO::FETCH_ASSOC);
  36. if($_COOKIE['session_key'] == $row['session_key']){
  37. $_SESSION['session_key'] = $_COOKIE['session_key'];
  38. $_SESSION['username'] = $_COOKIE['username'];
  39. $is_logged_in = true;
  40. }
  41. }
  42. if($is_logged_in === false){
  43. header("Location: ./login.php");
  44. }
  45. ?>
  46. <html lang = "en">
  47. <head>
  48. <title>OB2 | Login</title>
  49. <link href="chota.min.css" rel="stylesheet">
  50. </head>
  51. <body>
  52. </br>
  53. <!--
  54. <div class="is-center is-marginless">
  55. <h2 class="is-marginless">Online Bookmarks 2</h2>
  56. </div>
  57. <div class="is-center is-marginless">
  58. Logged in as <?php echo $_SESSION['username'] ?>
  59. </div> -->
  60. <div class="container is-full-width">
  61. <div class="row">
  62. <div class="col">
  63. <div class="card is-center">.col</div>
  64. </div>
  65. </div>
  66. </div>
  67. <?php
  68. ?>
  69. </body>
  70. </html>