Guest User

Login

a guest
May 17th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. //This is the code for User Login page//
  2.  
  3.  
  4. <?php
  5. //Start session
  6. session_start();
  7.  
  8. //Unset the variables stored in session
  9. unset($_SESSION['SESS_MEMBER_ID']);
  10. unset($_SESSION['SESS_FIRST_NAME']);
  11. unset($_SESSION['SESS_LAST_NAME']);
  12. ?>
  13. <html>
  14. <head>
  15. <title>
  16. Sales Management System
  17. </title>
  18. <link rel="shortcut icon" href="main/images/pos.jpg">
  19.  
  20. <link href="main/css/bootstrap.css" rel="stylesheet">
  21. <link href="button.css" rel="stylesheet">
  22.  
  23.  
  24.  
  25. <link rel="stylesheet" href="main/css/font-awesome.min.css">
  26.  
  27.  
  28.  
  29.  
  30. </head>
  31. <body background="bg.jpg">
  32.  
  33. <font style=" font:bold 45px 'Aleo'; text-shadow:px px px #000; color:#fff;"><center>Sales Management System</center></font>
  34.  
  35. <div id="login">
  36. <?php
  37. if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
  38. foreach($_SESSION['ERRMSG_ARR'] as $msg) {
  39. echo '<div style="color: red; text-align: center;">',$msg,'</div><br>';
  40. }
  41. unset($_SESSION['ERRMSG_ARR']);
  42. }
  43. ?>
  44. <form action="login.php" method="post">
  45.  
  46. <font style=" font:bold 25px 'Aleo'; text-shadow:px px px #000; color:#fff;"><center>Admin Login</center></font>
  47. <br>
  48.  
  49.  
  50. <div class="input-prepend">
  51. <span style="height:30px; width:25px;" class="add-on"><i class="icon-user icon-2x"></i></span><input style="height:40px;" type="text" name="username" border="5" Placeholder="Username" required/ ><br>
  52. </div>
  53. <br><div class="input-prepend">
  54. <span style="height:30px; width:25px;" class="add-on"><i class="icon-lock icon-2x"></i></span><input type="password" style="height:40px;" name="password" Placeholder="Password" required/><br>
  55. </div>
  56. <br><div class="qwe">
  57. <button class="myButton" href="dashboard.html" type="submit"><i class="icon-signin icon-large"></i> Submit</button>
  58. </div>
  59. </form>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </body><br><br><div align="center"><font style=" font:bold 25px 'Aleo'; text-shadow:px px px #000; color:#fff;">Developed by Amandeep Singh</font></div>
  65. </html>
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. //The Code for Login Validation page//
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. <?php
  91. //Start session
  92. session_start();
  93.  
  94. //Array to store validation errors
  95. $errmsg_arr = array();
  96.  
  97. //Validation error flag
  98. $errflag = false;
  99.  
  100. //Connect to mysql server
  101. $link = mysql_connect('localhost','root',"");
  102. if(!$link) {
  103. die('Failed to connect to server: ' . mysql_error());
  104. }
  105.  
  106. //Select database
  107. $db = mysql_select_db('sales', $link);
  108. if(!$db) {
  109. die("Unable to select database");
  110. }
  111.  
  112. //Function to sanitize values received from the form. Prevents SQL injection
  113. function clean($str) {
  114. $str = @trim($str);
  115. if(get_magic_quotes_gpc()) {
  116. $str = stripslashes($str);
  117. }
  118. return mysql_real_escape_string($str);
  119. }
  120.  
  121. //Sanitize the POST values
  122. $login = clean($_POST['username']);
  123. $password = clean($_POST['password']);
  124.  
  125. //Input Validations
  126. if($login == '') {
  127. $errmsg_arr[] = 'Username missing';
  128. $errflag = true;
  129. }
  130. if($password == '') {
  131. $errmsg_arr[] = 'Password missing';
  132. $errflag = true;
  133. }
  134.  
  135. //If there are input validations, redirect back to the login form
  136. if($errflag) {
  137. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  138. session_write_close();
  139. header("location: index.php");
  140. exit();
  141. }
  142.  
  143. //Create query
  144. $qry="SELECT * FROM user WHERE username='$login' AND password='$password'";
  145. $result=mysql_query($qry);
  146.  
  147. //Check whether the query was successful or not
  148. if($result) {
  149. if(mysql_num_rows($result) > 0) {
  150. //Login Successful
  151. session_regenerate_id();
  152. $member = mysql_fetch_assoc($result);
  153. $_SESSION['SESS_MEMBER_ID'] = $member['id'];
  154. $_SESSION['SESS_FIRST_NAME'] = $member['name'];
  155. $_SESSION['SESS_LAST_NAME'] = $member['position'];
  156. //$_SESSION['SESS_PRO_PIC'] = $member['profImage'];
  157. session_write_close();
  158. header("location: main/index.php");
  159. exit();
  160. }else {
  161. //Login failed
  162. header("location: index.php");
  163. exit();
  164. }
  165. }else {
  166. die("Query failed");
  167. }
  168. ?>
Add Comment
Please, Sign In to add comment