I’m trying to display error messages on the same page that submits a form (register_page.php). So in the script that executes the form submission, I create an array to hold all the error messages, and towards the end of the script I include a conditional at the end, which does the following if there are errors: First I convert the $errors array into a string, url encode it, then pass it into the url of the target page (register_page.php). Then on the target page, I retrieve the message through GET, url decode it, reconvert it to an array and try to print it out the contents of the array. So here is the excerpt of the conditional on the execution page:
[php]
//Display error messages.
} else {// if errors array is not empty
//Conver the errors array into a string
$errors_string = implode(" ", $errors);
//Encode the imploded string.
$message = urlencode($errors_string);
header("Location: register_page.php?message=$message");
}
[/php]
And here is the code for the target page:[code]
<div id="error">
<?php if(isset($_GET['message'])) {
//Decode the url
$errors_string = urldecode($_GET['message']);
//Explode the decoded errors string back to an array.
$errors = explode(" ", $errors_string);
echo '<h3>Error!</h3>
The following error(s) occured:<br />';
foreach ($errors as $msg) {
echo "$msg<br/>\n";
}
}
?>
</div> <!--closes error-->[/code]
Now everything works just fine, except that the error messages are printed one word per line for example
Your
email
is
not
a
valid
email
address.
I can’t seem to find the fluke in the code. Any ideas? Also is there any potential security risk for passing error messages in a url? No sensitive information is being transmitted. Just error messages.

