diff --git a/src/Response/Response.php b/src/Response/Response.php index 3ffc860..ea94a84 100644 --- a/src/Response/Response.php +++ b/src/Response/Response.php @@ -286,4 +286,22 @@ public function redirect(string $url) : object $this->body = null; return $this; } + + /** + * + * Tries to redirect back to the previous page + * + * @param string $fallback fallback url to redirect to + * + * @return self + * + */ + public function redirectBack(string $fallback = "") + { + if (isset($_SERVER["HTTP_REFERER"])) { + return $this->redirect($_SERVER["HTTP_REFERER"]); + } else { + return $this->redirect($fallback); + } + } }