¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.
JScms_redirect
The JScms_redirect
function is used to redirect the user to a specified URL with an optional HTTP status code.
It ensures proper redirection by setting the HTTP Location
header and stopping further script execution.
JScms_redirect($url, $code = 302)
$url
: (string) The target URL to which the user should be redirected. This URL is decoded using html_entity_decode
.$code
: (int) Optional. The HTTP status code for the redirection. Default is 302
(Found / Temporary Redirect).
This function does not return a value. It sends a Location
header to the browser and terminates the script using exit
.
<?php
// Redirect to the homepage with a 302 status code
JScms_redirect('https://example.com/home');
// Redirect to a 404 error page with a 404 status code
JScms_redirect('https://example.com/404', 404);
?>
$url
is properly validated and sanitized to prevent potential security issues such as open redirects.301
for permanent redirects.302
for temporary redirects.404
for not found pages.headers already sent
errors.$url
parameter is a valid and accessible URL.