Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Login.php
- <?php
- include('Verifylog.php'); // Includes Login Script
- if(isset($_SESSION['login_user'])){
- header("location:../profile.php");
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>de novo</title>
- <link href="style.css" rel="stylesheet" type="text/css">
- </head>
- <body>
- <div id="main">
- <div id="login">
- <h2>Login</h2>
- <form action="" method="post">
- <label>UserName :</label>
- <input id="name" name="username" placeholder="username"
- type="text">
- <label>Password :</label>
- <input id="password" name="password" placeholder="**********"
- type="password">
- <input name="submit" type="submit" value=" Login ">
- <span><?php echo $error; ?></span>
- </form>
- </div>
- </div>
- </body>
- </html>
- <?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("denovo", $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:../profile.php"); // Redirecting To Other Page
- } else {
- $error = "Username or Password is invalid";
- }
- mysql_close($connection); // Closing Connection
- }
- }
- ?>
- <?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("denovo", $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:login.php'); // Redirecting To Home Page
- }
- ?>
- table login
- id
- username
- password
- session_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement