redirectTo
The redirectTo function is used to redirect the user to a specified URL and optionally set a session message. It serves as a wrapper for JScms_redirect, allowing developers to include custom messages during redirection, such as success, error, or informational messages.
redirectTo($url, $messageKey = null, $message = null)
$url: (string) The target URL to which the user should be redirected.$messageKey: (string|null) Optional. The key used to store the message in the session, such as 'successmsg', 'errormsg', or 'infomsg'. Default is null.$message: (string|null) Optional. The message to store in the session under $messageKey. Default is null.This function does not return a value. It sets a session message (if provided) and redirects the user to the specified URL using JScms_redirect.
<?php
// Redirect to the homepage without a message
redirectTo(BASE_URL);
// Redirect to a page with a success message
redirectTo(BASE_URL, 'successmsg', $lang["successful"]);
// Redirect to a login page with an error message
redirectTo(BASE_URL, 'errormsg', $lang["login_required"]);
// Redirect to a profile page with an informational message
redirectTo(BASE_URL, 'infomsg', $lang["profile_updated"]);
?>
$url to prevent potential security vulnerabilities like open redirects.$messageKey values (e.g., 'successmsg', 'errormsg', 'infomsg') to ensure clarity when retrieving messages.$url parameter is a valid and accessible URL.$messageKey does not overwrite critical session keys unintentionally.