The correct way to do what you want is:
<?php
/* En la captura de tu pregunta aparenta estar definido así 'error' */
$error = [ 'error' => '<li>Tamaño máximo superado</li>' ];
$error = serialize($error);
$error = urlencode($error);
/* OJO: agregamos 'mensaje=' para que en el otro lado llegue como $_GET['mensaje'] */
header("Location: subidaarchivos.php?mensaje=" . $error);
After converting the matrix $error
in a string we must code it in URL with urlencode()
to be able to add it to the URL later, but in your example you are decoding it with urldecode()
.
And at the receiving end the work is simpler:
<?php
/* Comprobamos que ha llegado correctamente el campo 'error' */
if (isset($_GET['mensaje'])) {
/* Deshacemos el trabajo hecho por 'serialize' */
$error = unserialize($_GET['mensaje']);
// El contenido del error está en el índice 'error'
die($error['error']);
}
The data arrives correctly correctly formed to the content of the variable $_GET['mensaje']
, you only have to undo the work of serialize
to access the data again with unserialize
.
Finally, since it is a matrix, you must access the error
index to be able to show the content of the error.
URL generated:
subidaarchivos.php?mensaje=a%3A1%3A%7Bs%3A5%3A%22error%22%3Bs%3A33%3A%22%3Cli%3ETama%C3%B1o+m%C3%A1ximo+superado%3C%2Fli%3E%22%3B%7D
Workaround hiding data in URL
You can easily hide the data that appears in the URL using, for example, base64_encode()
.
<?php
/* En la captura de tu pregunta aparenta estar definido así 'error' */
$error = [ 'error' => '<li>Tamaño máximo superado</li>' ];
$error = serialize($error);
$error = base64_encode($error);
$error = urlencode($error);
/* OJO: agregamos 'error=' para que en el otro lado llegue como $_GET['mensaje'] */
header("Location: subidaarchivos.php?mensaje=" . $error);
And on the reception side:
<?php
/* Comprobamos que ha llegado correctamente el campo 'error' */
if (isset($_GET['mensaje'])) {
/* Deshacemos el trabajo hecho por base64_encode */
$error = base64_decode($_GET['mensaje']);
/* Deshacemos el trabajo hecho por 'serialize' */
$error = unserialize($error);
// El contenido del error está en el índice 'error'
die($error['error']);
}
Basically we introduce an additional step that encodes and decodes base64 the data that will appear in the URL, hiding its content or meaning at a glance:
URL generated:
subidaarchivos.php?mensaje=YToxOntzOjU6ImVycm9yIjtzOjMzOiI8bGk%2BVGFtYcOxbyBtw6F4aW1vIHN1cGVyYWRvPC9saT4iO30%3D