Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <?php
  2.  
  3. mysqli_connect('localhost', 'root', '', 'info') or die($connect_error);
  4.  
  5.  
  6. ?>
  7.  
  8. <?php
  9.  
  10. function sanitize($data) {
  11. mysqli_real_escape_string($connect,$data);
  12. }
  13.  
  14. function protect_page() {
  15. if (logged_in() === false) {
  16. header('Location:../../redirect.php');
  17. }
  18. }
  19.  
  20. function logged_in_redirect() {
  21. if (logged_in() === true) {
  22. header('Location: ../../dashboard.php');
  23. exit();
  24. }
  25. }
  26.  
  27. ?>
  28.  
  29. <?php
  30.  
  31. function user_exists($username) {
  32. $username = sanitize($username);
  33. $query = mysqli_query($connect,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
  34. mysqli_num_rows($query), 0) == 1) ? true : false;
  35. }
  36.  
  37. function logged_in() {
  38. return (isset($_SESSION['id'])) ? true : false;
  39. }
  40.  
  41. ?>
  42.  
  43. mysqli_connect('localhost', 'root', '', 'info') or die($connect_error);
  44.  
  45.  
  46. ?>
  47.  
  48. <?php
  49. include 'core/init.php';
  50.  
  51. if (user_exists('stole') === false) {
  52. echo 'exists';
  53. }
  54. die ();
  55.  
  56.  
  57. if (empty($_POST) === false) {
  58. $username = $_POST['username'];
  59. $password = $_POST['password'];
  60.  
  61. if(empty($username) === true || empty($password) === true) {
  62. $errors [] = 'Please enter a valid username and password';
  63. } else if (user_exists($username) === false) {
  64. $errors [] = 'We can't find that username. Have you registered? ';
  65.  
  66.  
  67. }
  68. }
  69.  
  70. ?>
  71.  
  72. <?php
  73.  
  74. $connect = mysqli_connect('localhost', 'root', '', 'info') or die($connect_error);
  75.  
  76.  
  77. ?>
  78.  
  79. <?php
  80.  
  81. function sanitize($data) {
  82. global $connect;
  83. mysqli_real_escape_string($connect,$data);
  84. }
  85.  
  86. function protect_page() {
  87. if (logged_in() === false) {
  88. header('Location:../../redirect.php');
  89. }
  90. }
  91.  
  92. function logged_in_redirect() {
  93. if (logged_in() === true) {
  94. header('Location: ../../dashboard.php');
  95. exit();
  96. }
  97. }
  98.  
  99. ?>
  100.  
  101. <?php
  102.  
  103. $connect = mysqli_connect('localhost', 'root', '', 'info') or die($connect_error);
  104.  
  105. function user_exists($username) {
  106. global $connect;
  107. $username = sanitize($username);
  108. $query = mysqli_query($connect,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
  109. mysqli_num_rows($query), 0) == 1) ? true : false;
  110. }
  111.  
  112. function logged_in() {
  113. return (isset($_SESSION['id'])) ? true : false;
  114. }
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement