'csrf')); } } else if (isset($_GET['next']) && $_GET['next'] == "admin") { header("Location: ./admin/"); } else { header('Location: index.php'); } exit; } if ((isset($_POST['username'])) && (isset($_POST['password'])) && ($_POST['username']!='') && ($_POST['password']!='')) { if (cavern_login($_POST['username'], $_POST['password']) == 1) { if (isset($_POST['next']) && trim($_POST['next']) == "admin") { header('Location: ./admin/'); } else if ((isset($_POST['next']) && filter_var($_POST['next'], FILTER_VALIDATE_URL)) || isset($_SERVER['HTTP_REFERER'])) { // redirect to previous page before login $next = (isset($_POST['next']) ? $_POST['next'] : $_SERVER['HTTP_REFERER']); // users login directly from navbar $url_data = parse_url($next); $len = strlen("index.php"); if (mb_substr($url_data['path'], -$len) === "index.php") { // the user was viewing the index page, so we just redirect him to index page header('Location: index.php?ok=login'); } else { if (!isset($url_data['query'])) { $url_data['query'] = "ok=login"; } else if (!strpos($url_data['query'], "ok=login")) { // for those already have url queries, such as 'post.php?pid=1' $url_data['query'] .= "&ok=login"; } $url = "{$url_data['path']}?{$url_data['query']}"; header("Location: $url"); } } else { // previous page doesn't exist, so we just redirect to default page header('Location: index.php?ok=login'); } } else { header('Location: index.php?err=login'); } exit; } else { $admin = (isset($_GET['next']) && trim($_GET['next']) == "admin"); ?>