Documentation

Redirect

Overview

App::redirect helps you to redirect current request to a new request or sub-request.

Usage

App::redirect(string $url, string $message = null, string $type = 'success')

Params

$url is the url to redirect to.

$message is the message to display on redirect. (Default value => null)

$type is the message type. (Default value => 'success')

Application

Situation

What if a user is logged out, but the user sends a request which needs an authorization?

Solution

We need to notify the users that they are logged out and send a page to let them log in first. Then they can access to their request.

Code

// Check if user is logged in
if (User::isGuest())
{
    // Store the request uri
    $return = base64_encode($_SERVER['REQUEST_URI']);
    // Require login and recall back if seccess
    App::redirect(
        Route::url('index.php?option=com_users&view=login&return=' . $return),
        'Please login to continue',
        'warning'
    );
}

Last modified:

  • Copyright © 2022 Hubzero
  • Powered by Hubzero®