Advertisement
blivori

login.php

Dec 16th, 2012
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1.  
  2.         <?php
  3.            
  4.             require_once('dbConfig.php');
  5.             require_once('functions.php');
  6.            
  7.             session_start();
  8.            
  9.             if ($_SESSION['logged_in'] == true) {
  10.            
  11.            
  12.                 redirect('../TASK2PHP/upload.php');
  13.            
  14.             } else {
  15.            
  16.             if ((!isset($_POST['username'])) || (!isset($_POST['password'])) OR (!ctype_alnum($_POST['username'])) ) {
  17.            
  18.            
  19.                     redirect('../TASK2PHP/index.php');
  20.                     echo 'You are not logged in.';
  21.            
  22.             }
  23.            
  24.             $mysqli = @new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
  25.            
  26.             if (mysqli_connect_errno()) {
  27.            
  28.             printf("Unable to login. Connection to database failed. %s", mysqli_connect_error());
  29.            
  30.             exit();
  31.            
  32.             }
  33.            
  34.             $username = $mysqli-> real_escape_string($_POST['username']);
  35.             $password = $mysqli-> real_escape_string($_POST['password']);
  36.            
  37.             $sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "'";
  38.            
  39.             $result = $mysqli-> query($sql);
  40.            
  41.             if (is_object($result) && $result->num_rows == 1) {
  42.            
  43.            
  44.             $_SESSION['logged_in'] = true;
  45.            
  46.             redirect('../TASK2PHP/upload.php');
  47.             echo 'You are now logged in ' , $username;
  48.            
  49.                    
  50.            
  51.             } else {
  52.            
  53.            
  54.             redirect('../TASK2PHP/index.php');
  55.            
  56.            
  57.             }
  58.        
  59.        
  60.         }
  61.        
  62.                        
  63.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement