Guest User

Untitled

a guest
Jul 9th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. <?php
  2. // Functions file:
  3. // ToDo: IPlocking (W.I.P)
  4. // ToDo: POST-check + if-statement for $bericht + locationheader (W.I.P)
  5.  
  6. function sqlsafe($data) {
  7. $data = mysql_real_escape_string($data);
  8. return $data;
  9. }
  10.  
  11.  
  12.  
  13. // Make MySQL-database connection
  14. @mysql_connect($server, $user,$pass) or die ("Can't connect to MySQL database server");
  15. @mysql_select_db($database) or die("Can't find database.");
  16.  
  17. // Start here the login action, and make the random hash
  18. if(($_SERVER['REQUEST_METHOD'] == "POST") && ($_POST['login'])) {
  19. $selectleden = mysql_query("SELECT * FROM $ledentabel WHERE username = '".sqlsafe($_POST['username'])."' AND password = '".sqlsafe(md5($_POST['password']))."'");
  20. if(mysql_num_rows($selectleden)) {
  21. // Ingelogd
  22. $hash = md5(uniqid(rand(), true));
  23. $get_id = mysql_query("SELECT id FROM ".$ledentabel." WHERE username = '".sqlsafe($_POST['username'])."' AND password = '".sqlsafe(md5($_POST['password']))."'");
  24. $fetch_id = mysql_fetch_assoc($get_id);
  25. $insert_session = mysql_query("INSERT INTO sessions (id, userid, hash, logintime) VALUES ('','".$fetch_id['id']."','".$hash."',NOW())");
  26.  
  27. // for debugging:
  28. #$bericht = "Ingelogd met hash: ".$hash." En je hebt id-nummer:".$fetch_id['id'];
  29.  
  30.  
  31. if ($insert_session) {
  32. setcookie ("id", $fetch_id['id'],time()+$_POST['sessiontime']);
  33. setcookie ("hash", $hash,time()+$_POST['sessiontime']);
  34. header('location:menu.php');
  35. } else {
  36. echo "Fout in de query: ".mysql_error();
  37. exit();
  38. }
  39. } else {
  40. // Foute pass
  41. $bericht = "<b>Je inloggegevens komen niet overeen met wat in de database staan.</b>";
  42. }
  43.  
  44.  
  45.  
  46. }
  47.  
  48. // here is the function for the login-check
  49. function checklogin() {
  50. if (mysql_num_rows(mysql_query("SELECT userid, `hash` FROM `sessions` WHERE `userid` = '".sqlsafe($_COOKIE['id'])."' AND `hash` = '".sqlsafe($_COOKIE['hash'])."'"))) {
  51. $return = TRUE;
  52. } else {
  53. $return = FALSE;
  54. }
  55.  
  56. return $return;
  57. }
  58.  
  59. // Data uit leden-tabel oproepen ($get_userdata['username'], $get_userdata['warnings']
  60. $get_data_qry = mysql_query("SELECT userid, `hash` FROM `sessions` WHERE `userid` = '".sqlsafe($_COOKIE['id'])."' AND `hash` = '".sqlsafe($_COOKIE['hash'])."'");
  61. $get_data = mysql_fetch_assoc($get_data_qry);
  62. $get_userdata = mysql_fetch_assoc(mysql_query("SELECT * FROM $ledentabel WHERE id = '".$get_data['userid']."'"));
  63.  
  64.  
  65.  
  66. ?>
Add Comment
Please, Sign In to add comment