]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Redirect back on login
authorValerie Pond <redacted>
Sat, 4 Feb 2023 16:44:12 +0000 (16:44 +0000)
committerValerie Pond <redacted>
Sat, 4 Feb 2023 16:44:12 +0000 (16:44 +0000)
This makes it so that when your session times out and you are redirected to the login page, you will be redirected back to the page you were on before you were logged out.

plugins/sql_auth/login.php
plugins/sql_auth/sql_auth.php

index 5d6739f031950eb228f8df80b6339c32f268e383..71bacfb4b39f86d4b1724aafbb63584902a17414 100644 (file)
@@ -4,6 +4,8 @@ require_once "../../common.php";
 require_once "SQL/user.php";
 
 $logout = false;
+$redirect = (isset($_GET['redirect'])) ? $_GET['redirect'] : BASE_URL;
+
 if (!empty($_GET['logout']))
 {
        if (!isset($_SESSION['id']))
@@ -29,8 +31,10 @@ if (!empty($_POST))
                }
                else if ($user->password_verify($_POST['password']))
                {
+                       var_dump($_GET);
+
                        $_SESSION['id'] = $user->id;
-                       header('Location: ' . BASE_URL);
+                       header('Location: ' . $redirect);
                        $user->add_meta("last_login", date("Y-m-d m:i:s"));
                }
                else
@@ -76,7 +80,7 @@ if (!empty($_POST))
 </script>
 <body role="document">
 <div class="container-fluid">
-<form method="post" action="login.php">
+<form method="post" action="login.php?redirect=<?php echo $redirect; ?>">
        <div class="modal" id="loginModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="loginModal" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
                <div class="modal-content">
index 856dc094eb7fab5e5015568caa232c7d4dff1e99..0f8486597fbfdf6eaf243a74fa0a663b4621886f 100644 (file)
@@ -55,6 +55,7 @@ class sql_auth
                }
        }
 
+       /* pre-Header hook */
        public static function session_start($n)
        {
                if (!isset($_SESSION))
@@ -65,13 +66,14 @@ class sql_auth
                do_log($_SESSION);
                if (!isset($_SESSION['id']) || empty($_SESSION))
                {
+                       $secure = ($_SERVER['HTTPS'] == 'on') ? "https://" : "http://";
+                       $current_url = "$secure$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
                        $tok = split($_SERVER['SCRIPT_FILENAME'], "/");
                        if ($check = security_check() && $tok[count($tok) - 1] !== "error.php") {
                                header("Location: " . BASE_URL . "plugins/sql_auth/error.php");
                                die();
                        }
-                       session_destroy();
-                       header("Location: ".BASE_URL."plugins/sql_auth/login.php");
+                       header("Location: ".BASE_URL."plugins/sql_auth/login.php?redirect=".urlencode($current_url));
                        die();
                }
                else