Reputation: 543
I was just wondering if there is any possible way of getting rid of the parameters in a link. For example, I have this redirecting the user back to the original form if any errors come up:
www.mywebsite.com/form.php?error_code=1021
But I don't want the user to see the error_code=1021.
How would I code it in PHP so that after it redirect to the page with the error, it looks like this to the user:
www.mywebsite.com/form.php
Upvotes: 2
Views: 96
Reputation: 12985
Use set_cookie()
to set the error as a url-specific cookie and use $_COOKIE['error_core']
when displaying the error to the user. Don't set an expiry date so the browser drops it on exit.
Upvotes: 0
Reputation: 254886
Sessions are overkill in this case.
It's much more convenient just not to redirect after a form validation.
That's it - render the form and validate by the same script. That way it will also be trivial to re-fill the form with the previous values.
There is no practical reasons to follow the PRG pattern in this particular case.
Upvotes: 2
Reputation: 3772
Have a look at the examples on the session_start page from the php manual, you can find it here: http://php.net/manual/en/function.session-start.php
Upvotes: 0
Reputation: 78994
You can take the advice in the comments and not redirect, or if you must, I would use sessions:
session_start();
$_SESSION['error_code'] = '1021';
header('Location: http://www.mywebsite.com/form.php');
exit;
Then in the form you would need session_start()
and then access $_SESSION['error_code']
.
Upvotes: 3