I have created a html page in php and upon submission i validates that page using PHP. After validating i want to show an alert msg to show its status like showing any greeting or request for re-enter.
I have dont validation. Now i m using
header( 'Location: http://localhost/assignment/WebForm.htm' ) ;
to redirect user to same page but with a alert msg at page load or something like that. What I need to do ?
When you use
header, you can’t output anything in the document’s body, making anyalert()ing impossible.A often used trick to achieve this is to delegate the
alert()ing to the target page:and then in WebForm.htm:
just remember to
htmlentities()the output when outputting the message.If you are already using sessions, for 100% security and elegant URLs, you could also generate a random key in PHP using
rand, store the message in$_SESSION["message_$randomKey"]and pass the key in the GET request. That way, the only thing the user sees in the URL is the key, and not the message.