Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $_SESSION['loggedIn'] = true;
- function is_logged() {
- if (isset($_SESSION['username'])) return $_SESSION['username'];
- else return false;
- }
- if( !isset($_SESSION['loggedIn']) && ($_SESSION['loggedIn'] != true) )
- {
- // redirect the user to login screen if the session variable is not set and its value is not true
- header('location: login.php');
- }
- ?>
- <html>
- <head>
- <title>Login</title>
- </head>
- <body>
- <?php
- if (!isset($_POST['submit'])){
- ?>
- <!-- The HTML login form -->
- <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
- Username: <input type="text" name="username" /><br />
- Password: <input type="password" name="password" /><br />
- <input type="submit" name="submit" value="Login" />
- </form>
- <?php
- } else {
- require_once("db_const.php");
- $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
- # check connection
- if ($mysqli->connect_errno) {
- echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
- exit();
- }
- $username = $_POST['username'];
- $password = $_POST['password'];
- $sql = "SELECT * from GEBRUIKERS WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
- $result = $mysqli->query($sql);
- if (!$result->num_rows == 1) {
- echo "<p>Invalid username/password combination</p>";
- } else {
- echo "<p>Logged in successfully</p>";
- // do stuffs
- }
- if (mysqli_num_rows($result) > 0) {
- // Output data of each row
- while($row = mysqli_fetch_assoc($result)) {
- $_SESSION['+login_user']=$user; // Initializing Session
- header("location: welcome.php"); // Redirecting To Other Page
- }
- }
- else {
- $error = "Username or Password is invalid";
- }
- mysqli_close($conn); // Closing Connection
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment