<?php 
    ob_start();
	session_start();
	
    $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";  
    $CurPageURL = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];  
	$slug = $_SERVER['REQUEST_URI'];
	if($slug == '/dashboard' || $slug == '/dashboard.php') {
		if(isset($_COOKIE['rememberme'])) {
			$logincookie = $_COOKIE['rememberme'];
			$lgcookie = base64_decode($logincookie);
			$lgusr = explode (':', $lgcookie);
			$loginuser = $lgusr[0];
			$_SESSION['username'] = $username;
			$_SESSION['status'] = "login";
		} 
		if(isset($_SESSION['username']) && !empty($_SESSION['username'])) {
			echo $_SESSION['username'];
			//header('Location: /dashboard.php'); exit;	
		/*	$sql = $connection->prepare("SELECT * FROM users WHERE username=:username");
			$sql->bindParam('username', $_SESSION['username']);
			$sql->execute();
			$user = $sql->fetch(PDO::FETCH_ASSOC);

			if ($user) {
                $userId = $user['id'];
				$username = $user['username'];
				$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
				if($user['akses'] == 'op') {
					if($path != '/account-setting' && $path != '/chat' && $path != '/chat-tag' && $path != '/add-chat-tag' && $path != '/edit-chat-tag') {
						header('Location: /account-setting'); exit;
					}
				}
				if($user['akses'] == 'user') {
					if($path != '/dashboard' && $path != '/account-setting') {
						header('Location: /dashboard'); exit;
					}
				}
			} */
		} else {
			header('Location: /login.php'); exit;	
		} 
	}  
?>