Guest User

Ini filenya

a guest
May 15th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.22 KB | None | 0 0
  1. ADMIN.php
  2.  
  3. <?php
  4. include('session.php');
  5. ?>
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <title>Your Home Page</title>
  10. <link href="style.css" rel="stylesheet" type="text/css">
  11. </head>
  12. <body>
  13. <div id="profile">
  14. Welcome : <i><?php echo $login_session; ?></i></b>
  15. <a href="logout.php">Log Out</a></b>
  16. </div>
  17. </body>
  18. </html>
  19.  
  20.  
  21. SESSION.PHP
  22.  
  23. <?php
  24. // Establishing Connection with Server by passing server_name, user_id and password as a parameter
  25. $connection = mysql_connect("localhost", "root", "");
  26. // Selecting Database
  27. $db = mysql_select_db("dbantrian", $connection);
  28. session_start();// Starting Session
  29. // Storing Session
  30. $user_check=$_SESSION['login_user'];
  31. // SQL Query To Fetch Complete Information Of User
  32. $ses_sql=mysql_query("select username from login where username='$user_check'", $connection);
  33. $row = mysql_fetch_assoc($ses_sql);
  34. $login_session =$row['username'];
  35. if(!isset($login_session)){
  36. mysql_close($connection); // Closing Connection
  37. header('Location: admin.php'); // Redirecting To Home Page
  38. }
  39. ?>
  40.  
  41.  
  42. LOGOUT
  43.  
  44. <?php
  45. session_start();
  46. if(session_destroy()) // Destroying All Sessions
  47. {
  48. header("Location: index.php"); // Redirecting To Home Page
  49. }
  50. ?>
  51.  
  52.  
  53. INDEX.PHP
  54.  
  55. <?php
  56. include('login.php'); // Includes Login Script
  57.  
  58. if(isset($_SESSION['login_user'])){
  59. header("location: admin.php");
  60. }
  61. ?>
  62. <!DOCTYPE html>
  63. <html >
  64. <head>
  65.   <meta charset="UTF-8">
  66.   <title>Login Form</title>
  67.   <link rel="stylesheet" href="css/style.css">
  68.   <link rel="stylesheet" href="css/normalize.min.css">
  69.   </head>
  70.  
  71. <body>
  72.   <div class="login">
  73.     <h1>Login</h1>
  74.     <form method="post" action="" autocomplete="off">
  75.         <input type="text" name="u" placeholder="Username" required="required" />
  76.         <input type="password" name="p" placeholder="Password" required="required" />
  77.         <button type="submit" class="btn btn-primary btn-block btn-large" name="btn-login">Masuk</button>
  78.         <span><?php echo $error; ?></span>
  79.     </form>
  80. </div>
  81. </body></html>
  82.  
  83.  
  84.  
  85. LOGIN.PHP
  86.  
  87. <?php
  88. session_start(); // Starting Session
  89. $error=''; // Variable To Store Error Message
  90. if (isset($_POST['submit'])) {
  91. if (empty($_POST['username']) || empty($_POST['password'])) {
  92. $error = "Username or Password is invalid";
  93. }
  94. else
  95. {
  96. // Define $username and $password
  97. $username=$_POST['username'];
  98. $password=$_POST['password'];
  99. // Establishing Connection with Server by passing server_name, user_id and password as a parameter
  100. $connection = mysql_connect("localhost", "root", "");
  101. // To protect MySQL injection for Security purpose
  102. $username = stripslashes($username);
  103. $password = stripslashes($password);
  104. $username = mysql_real_escape_string($username);
  105. $password = mysql_real_escape_string($password);
  106. // Selecting Database
  107. $db = mysql_select_db("company", $connection);
  108. // SQL query to fetch information of registerd users and finds user match.
  109. $query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
  110. $rows = mysql_num_rows($query);
  111. if ($rows == 1) {
  112. $_SESSION['login_user']=$username; // Initializing Session
  113. header("location: admin.php"); // Redirecting To Other Page
  114. } else {
  115. $error = "Username or Password is invalid";
  116. }
  117. mysql_close($connection); // Closing Connection
  118. }
  119. }
  120. ?>
Add Comment
Please, Sign In to add comment