Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ADMIN.php
- <?php
- include('session.php');
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Your Home Page</title>
- <link href="style.css" rel="stylesheet" type="text/css">
- </head>
- <body>
- <div id="profile">
- Welcome : <i><?php echo $login_session; ?></i></b>
- <a href="logout.php">Log Out</a></b>
- </div>
- </body>
- </html>
- SESSION.PHP
- <?php
- // Establishing Connection with Server by passing server_name, user_id and password as a parameter
- $connection = mysql_connect("localhost", "root", "");
- // Selecting Database
- $db = mysql_select_db("dbantrian", $connection);
- session_start();// Starting Session
- // Storing Session
- $user_check=$_SESSION['login_user'];
- // SQL Query To Fetch Complete Information Of User
- $ses_sql=mysql_query("select username from login where username='$user_check'", $connection);
- $row = mysql_fetch_assoc($ses_sql);
- $login_session =$row['username'];
- if(!isset($login_session)){
- mysql_close($connection); // Closing Connection
- header('Location: admin.php'); // Redirecting To Home Page
- }
- ?>
- LOGOUT
- <?php
- session_start();
- if(session_destroy()) // Destroying All Sessions
- {
- header("Location: index.php"); // Redirecting To Home Page
- }
- ?>
- INDEX.PHP
- <?php
- include('login.php'); // Includes Login Script
- if(isset($_SESSION['login_user'])){
- header("location: admin.php");
- }
- ?>
- <!DOCTYPE html>
- <html >
- <head>
- <meta charset="UTF-8">
- <title>Login Form</title>
- <link rel="stylesheet" href="css/style.css">
- <link rel="stylesheet" href="css/normalize.min.css">
- </head>
- <body>
- <div class="login">
- <h1>Login</h1>
- <form method="post" action="" autocomplete="off">
- <input type="text" name="u" placeholder="Username" required="required" />
- <input type="password" name="p" placeholder="Password" required="required" />
- <button type="submit" class="btn btn-primary btn-block btn-large" name="btn-login">Masuk</button>
- <span><?php echo $error; ?></span>
- </form>
- </div>
- </body></html>
- LOGIN.PHP
- <?php
- session_start(); // Starting Session
- $error=''; // Variable To Store Error Message
- if (isset($_POST['submit'])) {
- if (empty($_POST['username']) || empty($_POST['password'])) {
- $error = "Username or Password is invalid";
- }
- else
- {
- // Define $username and $password
- $username=$_POST['username'];
- $password=$_POST['password'];
- // Establishing Connection with Server by passing server_name, user_id and password as a parameter
- $connection = mysql_connect("localhost", "root", "");
- // To protect MySQL injection for Security purpose
- $username = stripslashes($username);
- $password = stripslashes($password);
- $username = mysql_real_escape_string($username);
- $password = mysql_real_escape_string($password);
- // Selecting Database
- $db = mysql_select_db("company", $connection);
- // SQL query to fetch information of registerd users and finds user match.
- $query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
- $rows = mysql_num_rows($query);
- if ($rows == 1) {
- $_SESSION['login_user']=$username; // Initializing Session
- header("location: admin.php"); // Redirecting To Other Page
- } else {
- $error = "Username or Password is invalid";
- }
- mysql_close($connection); // Closing Connection
- }
- }
- ?>
Add Comment
Please, Sign In to add comment