Guest User

Untitled

a guest
May 10th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if (isset($_SESSION["manager"])){
  4.  header("location: index.php");
  5.  exit();
  6.  }
  7.  ?>
  8.  
  9. <?php
  10. //Parse the login form if the user has filled it out and pressed "Log in"
  11.  
  12. if (isset($_POST["username"]) && isset($_POST["password"])){
  13.  
  14.     $manager = preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);//filter everything but numbers & letters
  15.     $password = preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);//filter everything but numbers & letters
  16.     //connect to the MySQL database
  17.     include ("/home/lateral/public_html_com533/Scripts/connect_to_mysql.php");
  18.     $sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); //query the person
  19.     //------MAKE SURE PERSON EXISTS IN DATABASE ------
  20.     $existCount= mysql_num_rows($sql); //count the row nums
  21.     if ($existCount == 1) {// evaluate the count
  22.         while($row = mysql_fetch_array($sql)){
  23.             $id = $row["id"];
  24.             }
  25.             $_SESSION["id"] = $id;
  26.             $_SESSION["manager"] = $manager;
  27.             $_SESSION["password"] = $password;
  28.             header("location: index.php");
  29.             exit();
  30.             }else{
  31.                 echo 'That information is incorrect, try again <a href="index.php">Click here</a>';
  32.                 exit();
  33.                 }
  34.             }
  35. ?>
  36.  
  37. <?php # Script 3.4 - index.php
  38. $page_title = 'Store Admin Page';
  39. include ("../includes/header.php");
  40. ?>
  41.  
  42. <h2>Please log in to manage the store</h2>
  43.  
  44. <form id="" method="post" action="admin_login.php">
  45.  
  46. <label for="username" Username:</label>
  47. <input name="username" placeholder="Username" type="text" id="username" size="40"/>
  48.  
  49. <label for="password" Password:</label>
  50. <input name="password" placeholder="Password" type="password" id="password" size="40"/>
  51.  
  52. <label>
  53.     <input type="submit" name="button" id="button" value="login"/>
  54. </label>
  55. </form>
  56.  
  57.  
  58.  
  59. <?php
  60. include ('../includes/footer.php');
  61. ?>
Add Comment
Please, Sign In to add comment