Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php //Start the Session
- session_start();
- require('connect.php');
- if (isset($_POST['username']) and isset($_POST['password']))
- {
- //3.1.1 Assigning posted values to variables.
- $username = $_POST['username'];
- $password = $_POST['password'];
- //3.1.2 Checking if the values exist in the database
- $checkLogin = $connection->query("SELECT * FROM users
- where (username='$username' && password='$password')");
- $numRows = $checkLogin->fetchColumn();
- //3.1.2 If the posted values are equal to the database values, then session will be created for the user.
- if ($numRows >= 1){
- $_SESSION['username'] = $username;
- }else{
- //3.1.3 If the login credentials doesn't match, he will be shown with an error message.
- echo '<script>window.alert("Invalid Login Credentials")</script>';
- }
- }
- //3.1.4 if the user is logged in Greets the user with message
- if (isset($_SESSION['username'])){
- $username = $_SESSION['username'];
- echo "Hi " . $username . "
- ";
- echo "This is the Members Area";
- echo "<a href='logout.php'>Logout</a>";
- echo $username;
- }else{
- //3.2 When the user visits the page first time, simple login form will be displayed.
- ?>
- <!DOCTYPE html>
- <head>
- <title>CodingCyber - Simple Login Script</title>
- <link rel="stylesheet" type="text/css" href="style.css" />
- </head>
- <body>
- <!-- Form for logging in the users -->
- <div class="register-form">
- <?php
- if(isset($msg) & !empty($msg)){
- echo $msg;
- }
- ?>
- <h1>Login</h1>
- <form action="login.php" method="POST">
- <p><label>User Name : </label>
- <input id="username" type="text" name="username" placeholder="username" /></p>
- <p><label>Password : </label>
- <input id="password" type="password" name="password" placeholder="password" /></p>
- <a class="btn" href="register.php">Signup</a>
- <input class="btn register" type="submit" name="submit" value="Login" />
- </form>
- </div>
- <?php } ?>
- </body>
- </html>
- <?php
- session_start();
- $username = '';
- $password = '';
- $confirmPassword = '';
- $email = '';
- echo $username;
- unset($_POST['username']);
- unset($password);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement