Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.82 KB | None | 0 0
  1. session_start();
  2. $fields_error = "";
  3. $fields_error1 = "";
  4. $error = "";
  5. $mysqli = new mysqli("localhost", "root", "heihei", "innlogging") or die("cannot connect");
  6.  
  7. if(isset($_POST['Register'])){
  8.     header("location:register.php");
  9. }
  10. if (isset($_POST['Submit'])) {
  11.     if (empty($_POST['username']) || trim($_POST['username']) == "") {
  12.         $fields_error = "Username is required";
  13.         header("location:mainpage.php");
  14.     } else {
  15.         $username = $mysqli ->real_escape_string(htmlspecialchars($_POST['username'], ENT_QUOTES, 'UTF-8'));
  16.     }
  17.  
  18.     if (empty($_POST['password']) || trim($_POST['password']) == '') {
  19.         $fields_error1 = "Password is required";
  20.         header("location:mainpage.php");
  21.  
  22.     } else {
  23.         $password = $mysqli->real_escape_string(sha1(md5($_POST['password'])));
  24.     }
  25.  
  26.     if (empty($fields_error) && empty($fields_error1)) {
  27.  
  28.  
  29.  
  30.        $result = $mysqli->query("SELECT * FROM users WHERE username='$username' AND pass='$password'");
  31.  
  32.  
  33.         $data = $result->num_rows;
  34.  
  35.  
  36.         if ($data) {
  37.             $_SESSION["username"] = $username;
  38.             $_SESSION["isloggedin"] = true;
  39.             $_SESSION[$mysqli];
  40.             $result2 = $mysqli ->query("SELECT * FROM users WHERE username='$username' AND pass='$password' AND isadmin='1'");
  41.             $data2 = $result2 -> num_rows;
  42.             if($data2){
  43.                 $_SESSION["isadmin"] = 1;
  44.             }
  45.             else{
  46.                 $_SESSION["isadmin"] = 0;
  47.             }
  48.  
  49.             echo htmlspecialchars(strip_tags($_POST['username']), ENT_QUOTES, 'UTF-8');
  50.  
  51.             header("location:mainpage.php");
  52.  
  53.         } else {
  54.  
  55.             header("location:mainpage.php");
  56.             $error = "OOOPS..Username or Password is wrong!!!";
  57.         }
  58.  
  59.         $mysqli->close();
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement