Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. <?php
  2. $mysql_hostname = "localhost";
  3. $mysql_user = "root";
  4. $mysql_password = "";
  5. $mysql_database = "simple_login";
  6. $prefix = "";
  7. $bd = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password, $mysql_database) or die("Could not connect database");
  8. ?>
  9.  
  10. <?php
  11. //Start session
  12. session_start();
  13.  
  14. //Include database connection details
  15. require_once('connection.php');
  16.  
  17. //Array to store validation errors
  18. $errmsg_arr = array();
  19.  
  20. //Validation error flag
  21. $errflag = false;
  22.  
  23. //Function to sanitize values received from the form. Prevents SQL injection
  24. function clean($str) {
  25. $str = @trim($str);
  26. if(get_magic_quotes_gpc()) {
  27. $str = stripslashes($str);
  28. }
  29. return mysqli_real_escape_string($str);
  30. }
  31.  
  32. //Sanitize the POST values
  33. $username = clean($_POST['username']);
  34. $password = clean($_POST['password']);
  35.  
  36. //Input Validations
  37. if($username == '') {
  38. $errmsg_arr[] = 'Username missing';
  39. $errflag = true;
  40. }
  41. if($password == '') {
  42. $errmsg_arr[] = 'Password missing';
  43. $errflag = true;
  44. }
  45.  
  46. //If there are input validations, redirect back to the login form
  47. if($errflag) {
  48. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  49. session_write_close();
  50. header("location: index.php");
  51. exit();
  52. }
  53.  
  54. //Create query
  55. $qry="SELECT * FROM member WHERE username='$username' AND password='$password'";
  56. $result=mysqli_query($qry);
  57.  
  58. //Check whether the query was successful or not
  59. if($result) {
  60. if(mysqli_num_rows($result) > 0) {
  61. //Login Successful
  62. session_regenerate_id();
  63. $member = mysqli_fetch_assoc($result);
  64. $_SESSION['SESS_MEMBER_ID'] = $member['mem_id'];
  65. $_SESSION['SESS_FIRST_NAME'] = $member['username'];
  66. $_SESSION['SESS_LAST_NAME'] = $member['password'];
  67. session_write_close();
  68. header("location: home.php");
  69. exit();
  70. }else {
  71. //Login failed
  72. $errmsg_arr[] = 'user name and password not found';
  73. $errflag = true;
  74. if($errflag) {
  75. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  76. session_write_close();
  77. header("location: index.php");
  78. exit();
  79. }
  80. }
  81. }else {
  82. die("Query failed");
  83. }
  84. ?>
  85.  
  86. <?php
  87. //require_once('auth.php');
  88. ?>
  89. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  90. <html xmlns="http://www.w3.org/1999/xhtml">
  91. <head>
  92. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  93. <title>Untitled Document</title>
  94. <style type="text/css">
  95. <!--
  96. .style1 {
  97. font-size: 36px;
  98. font-weight: bold;
  99. }
  100. -->
  101. </style>
  102. </head>
  103.  
  104. <body>
  105. <p align="center" class="style1">Login successfully </p>
  106. <p align="center">This page is the home, you can put some stuff here......</p>
  107. <p align="center"><a href="index.php">logout</a></p>
  108. </body>
  109. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement