I have two pages:page1.php which consists of an associative array containing potential error messages from a form.
$errors array:
Array ( [password] => password is required. [email] => email is required. )
This array could contain more errors or it could contain less.
Im trying to pass it via url to another page to be displayed next to the corrosponding form fields.
page1.php:
$a = http_build_query($errors);
header("Location: /test/page2.php?errors=".$a);
exit();
URL:
http://localhost/test/page2.php?errors=password=password+is+required.&email=email+is+required.
However the url doesnt seem to be displaying correctly and when I get redirected to page2.php when I retrieve the $errors array, its no longer an array.
page2.php:
if(isset($_GET['errors'])){
$errors = $_GET['errors'];
print_r($errors);
$errors:
password=password is required.
Im trying to get the $errors array to display exactly like it does on page1.php before it is sent via url.
EDIT: NEW URL:
http://localhost/test/page2.php?a=errors%5Bpassword%5D=password+is+required.&errors%5Bemail%5D=email+is+required.
http_build_queryuses the array keys as GET parameters to the url, no need to prependerrors=. You could use something like$params = array("errors" => $errors); $a = http_build_query($params);if you need them to be named correctly. This would resullt in?errors[email]=...etc. GET parameters.$errorsarray in the first place? Can you add the new code to your question (with the generated URL)?