Is there a way to send some attributes when redirecting with header() function?
I would like to send some error message when redirecting(PHP5).
I know that I could just show error page for a 5 seconds or so and then redirect. Or redirect with query in link, but that's not the point.
Somethin like this:
header('Location: /mvc/index.php', $some_attributes);
and how to get them on index page?
Btw, I think that Location can't be relative, am I right?
A URL is a URL. You can pass data in it the same way as any other URL (i.e. encode it in a query string then read them with $_GET
).
Btw, I think that Location can't be relative, am I right?
Yes. Most browsers will perform error recovery on relative URIs in location headers (Lynx will do so while flashing a warning at the user), but the specification requires that they be absolute.
You can use it like this
header('Location: /mvc/index.php?attr='.$some_attributes);
and retrieve it like this in index.php
echo $_GET['attr'];
If your var is an Array:
header('Location: /mvc/index.php?'.http_build_query($some_attributes));
You can put the error message in session, redirect, display the error message on the error page and remove it from the session afterwards.