Guest User

Untitled

a guest
Jan 30th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. <?php
  2. $rdbms = "mysql";
  3. $host = "localhost";
  4. $db = "taitaja";
  5. $user = "root";
  6. $pass = "";
  7. $charset = "utf8";
  8.  
  9. $opt = [
  10. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  11. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  12. PDO::ATTR_EMULATE_PREPARES => false,
  13. ];
  14. $connectionString = "$rdbms:host=$host;dbname=$db;charset=$charset";
  15.  
  16. $pdo = new PDO($connectionString, $user, $pass, $opt);
  17.  
  18. if (isset($_POST['submit'])) {
  19. //lomakkeen vastaanotto
  20. $tunnus = filter_input(INPUT_POST, 'tunnus', FILTER_SANITIZE_STRING);
  21. $salasana = filter_input(INPUT_POST, 'salasana', FILTER_SANITIZE_EMAIL);
  22.  
  23.  
  24.  
  25. if (empty($tunnus) or empty($salasana)) {
  26. $errorMsg = "Syötä sekä käyttäjätunnus että salasana";
  27. } else {
  28. $sql = "SELECT * FROM kayttaja WHERE tunnus=?";
  29. $pdo = new PDO($connectionString, $user, $pass, $opt);
  30. $statement = $pdo->prepare($sql);
  31. $statement->execute(array($tunnus));
  32.  
  33. $user = $statement->fetch();
  34. if ($user) {
  35.  
  36. if (password_verify($salasana, $user["salasana"])) {
  37.  
  38. //onnistunut kirjautuminen
  39. session_start();
  40. $_SESSION["loggedin"] = $user["tunnus"];
  41. header("Location: entries.php");
  42. } else {
  43. $errorMsg = "Käyttäjätunnus tai salasana väärin<br>";
  44. }
  45. } else {
  46. $errorMsg = "Käyttäjätunnus tai salasana väärin<br>";
  47. }
  48. }
  49. }
  50. ?>
  51. <!DOCTYPE html>
  52. <html>
  53. <head>
  54. <meta charset="UTF-8">
  55. <title>Kirjautuminen</title>
  56. <style>
  57. body {
  58. font-size: 62.5%;
  59. background-color: white;
  60. font-family: sans-serif;
  61. }
  62.  
  63. #wrapper {
  64.  
  65. }
  66.  
  67. #content {
  68. width: 50%;
  69. margin-left: auto;
  70. margin-right: auto;
  71. font-size: 1.8em;
  72. }
  73. ul {
  74. float: left;
  75. width: 40%;
  76.  
  77. }
  78.  
  79. ul li {
  80. box-sizing: border-box;
  81. float: left;
  82. width: 30%;
  83. list-style-type: none;
  84. font-size: 1.8em;
  85. margin-left: 10px;
  86. border: 1px solid white;
  87. border-radius: 5px;
  88. padding: 5px;
  89. background-color: white;
  90. text-align: center;
  91.  
  92. }
  93.  
  94. ul li a {
  95. text-decoration: none;
  96. color: black;
  97. }
  98.  
  99. ul li:hover {
  100. background-color: #64bff8;
  101. border: 1px solid #64bff8;
  102. }
  103.  
  104. #title {
  105. clear:both;
  106. text-align: center;
  107. margin-bottom: 50px;
  108. font-size: 3.5em;
  109. font-weight: bold;
  110. color: #555;
  111. padding-top: 2.5em;
  112. }
  113.  
  114. form {
  115. width: 50%;
  116. margin-left: auto;
  117. margin-right: auto;
  118. border: 1px #b5e1fb solid;
  119. border-radius: 5px;
  120. padding: 25px;
  121. background-color: #54b8f7;
  122. }
  123.  
  124. form label {
  125. display:inline-block;
  126. float: left;
  127. padding-top: 5px;
  128. text-align: right;
  129. width: 100px;
  130. }
  131.  
  132. form input {
  133. margin-top: 5px;
  134. margin-bottom: 5px;
  135. display:inline-block;
  136. vertical-align:middle;
  137. margin-left:20px
  138. }
  139.  
  140. #button1 {
  141. background-color: #139df4;
  142. border: 2px solid #139df4;
  143. width: 40%;
  144. height: 40px;
  145. margin-left: 30%;
  146. margin-right: 30%;
  147. margin-top: 30px;
  148. margin-bottom: 20px;
  149. border-radius: 5px;
  150. font-size: 1em;
  151. }
  152.  
  153. #button1:hover {
  154. background-color: #0a7fca;
  155. border: 2px solid #0a7fca;
  156. }
  157.  
  158.  
  159. #lajit {
  160. margin-top: 70px;
  161. }
  162.  
  163. #active {
  164. box-sizing: border-box;
  165. float: left;
  166. width: 30%;
  167. list-style-type: none;
  168. font-size: 1.8em;
  169. margin-left: 10px;
  170. border: 1px solid white;
  171. border-radius: 5px;
  172. padding: 5px;
  173. background-color: white;
  174. text-align: center;
  175. background-color: #64bff8;
  176. border: 1px solid #64bff8;
  177. }
  178.  
  179. nav {
  180.  
  181. }
  182.  
  183. footer {
  184. text-align: center;
  185. font-size: 1.3em;
  186. color: grey;
  187. margin-top: 3em;
  188. max-width: 100%;
  189. min-width: 100%;
  190. }
  191.  
  192. </style>
  193. </head>
  194. <body>
  195. <div id="wrapper">
  196. <nav>
  197. <ul>
  198. <li id="active"><a href="login.php">Kirjaudu</a></li>
  199. <li><a href="index.php">Ilmoittaudu</a></li>
  200. <li><a href="entries.php">Ilmoittautumiset</a></li>
  201. </ul>
  202. </nav>
  203. <p id="title">Kirjautuminen</p>
  204. <?php
  205. if (isset($errorMsg)) {
  206. echo "<p>$errorMsg></p>";
  207. }
  208. ?>
  209. <div id="content">
  210. <form method="POST">
  211. <p>
  212. <label for="tunnus">Käyttäjätunnus</label>
  213. <input type="text" name="tunnus">
  214. </p>
  215. <p>
  216. <label for="salasana">Salasana</label>
  217. <input type="password" name="salasana">
  218. </p>
  219. <button id="button1" name="submit" value="login">Kirjaudu</button>
  220. </form>
  221. </div>
  222. </div>
  223. </body>
  224. </html>
Add Comment
Please, Sign In to add comment