Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require("mainconfig.php");
- $msg_type = "nothing";
- $cookie = $_COOKIE['cookie'];
- if (isset($_SESSION['user'])) {
- header("Location: ".$cfg_baseurl);
- } else {
- if ($cookie <> "") {
- $check_user = mysqli_query($db, "SELECT * FROM users WHERE cookie = '$cookie'");
- $data_user = mysqli_fetch_assoc($check_user);
- if (mysqli_num_rows($check_user) == 1) {
- $_SESSION['user'] = $data_user;
- header("Location: ".$cfg_baseurl);
- } else {
- header("Location: ".$cfg_baseurl."logout.php");
- }
- } else {
- if (isset($_POST['login'])) {
- $post_username = mysqli_real_escape_string($db, trim($_POST['username']));
- $post_password = mysqli_real_escape_string($db, trim($_POST['password']));
- $post_remember = $_POST['remember'];
- if (empty($post_username) || empty($post_password)) {
- $msg_type = "error";
- $msg_content = "<b>Failed:</b> Please fill all input.";
- } else {
- $check_user = mysqli_query($db, "SELECT * FROM users WHERE username = '$post_username'");
- if (mysqli_num_rows($check_user) == 0) {
- $msg_type = "error";
- $msg_content = "<b>Failed:</b> Incorrect username or password. $post_remember";
- } else {
- $data_user = mysqli_fetch_assoc($check_user);
- if ($post_password <> $data_user['password']) {
- $msg_type = "error";
- $msg_content = "<b>Failed:</b> Incorrect username or password.";
- } else if ($data_user['status'] == "Suspended") {
- $msg_type = "error";
- $msg_content = "<b>Failed:</b> Account suspended.";
- } else if ($post_password == $data_user['password']) {
- if ($post_remember == 1) {
- $rand_key = random(20);
- setcookie("cookie", $rand_key, time() + (86400 * 30));
- mysqli_query($db, "UPDATE users SET cookie = '$rand_key' WHERE username = '$post_username'");
- }
- $_SESSION['user'] = $data_user;
- header("Location: ".$cfg_baseurl);
- }
- }
- }
- }
- }
- include("lib/header.php");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement