Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('included')){
  4. die('You cannot access this file directly!');
  5. }
  6.  
  7. //log user in ---------------------------------------------------
  8. function login($user, $pass){
  9.  
  10. //strip all tags from variable
  11. $user = strip_tags(mysql_real_escape_string($user));
  12. $pass = strip_tags(mysql_real_escape_string($pass));
  13.  
  14. $pass = md5($pass);
  15.  
  16. // check if the user id and password combination exist in database
  17. $sql = "SELECT * FROM members WHERE username = '$user' AND password = '$pass'";
  18. $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
  19.  
  20. if (mysql_num_rows($result) == 1) {
  21. // the username and password match,
  22. // set the session
  23. $_SESSION['authorized'] = true;
  24.  
  25. // direct to admin
  26. header('Location: '.DIRADMIN);
  27. exit();
  28. } else {
  29. // define an error message
  30. $_SESSION['error'] = 'Sorry, wrong username or password';
  31. }
  32. }
  33.  
  34. function logged_in() {
  35. if($_SESSION['authorized'] == true) {
  36. return true;
  37. } else {
  38. return false;
  39. }
  40. }
  41.  
  42. function login_required() {
  43. if(logged_in()) {
  44. return true;
  45. } else {
  46. header('Location: '.DIRADMIN.'login.php');
  47. exit();
  48. }
  49. }
  50.  
  51. function logout(){
  52. unset($_SESSION['authorized']);
  53. header('Location: '.DIRADMIN.'login.php');
  54. exit();
  55. }
  56.  
  57. function messages() {
  58. $message = '';
  59. if($_SESSION['success'] != '') {
  60. $message = '<div class="msg-ok">'.$_SESSION['success'].'</div>';
  61. $_SESSION['success'] = '';
  62. }
  63. if($_SESSION['error'] != '') {
  64. $message = '<div class="msg-error">'.$_SESSION['error'].'</div>';
  65. $_SESSION['error'] = '';
  66. }
  67. echo "$message";
  68. }
  69.  
  70. function errors($error){
  71. if (!empty($error))
  72. {
  73. $i = 0;
  74. while ($i < count($error)){
  75. $showError.= "<div class="msg-error">".$error[$i]."</div>";
  76. $i ++;}
  77. echo $showError;
  78. }// close if empty errors
  79. } // close function
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement