Display a warning message on a web page when redirecting from one page to another when the page loads

I created an html page in php and after submitting I check this page with PHP. After checking, I want to show a warning message to show its status, for example, to show a greeting or a request for re-entry.

I have no verification. Now i use

header( 'Location: http://localhost/assignment/WebForm.htm' ) ; 

redirect the user to the same page, but with an msg notification when the page loads, or something like that. What should I do?

+1
source share
2 answers

When you use header , you cannot output anything in the body of the document, making any alert() impossible impossible.

A commonly used trick for this is delegating alert() ing to the landing page:

 header( 'Location: http://localhost/assignment/WebForm.htm?alert='. urlencode("Hello!")) ; 

and then in WebForm.htm:

  <?php if (isset($_GET["alert"])): ?> <script type="text/javascript"> alert("<?php echo htmlentities(urldecode($_GET["alert"])); ?>"); </script> <?php endif; ?> 

just remember the htmlentities() output when outputting the message.

If you already use sessions for 100% security and elegant URLs, you can also create a random key in PHP using rand , save the message in $_SESSION["message_$randomKey"] and pass the key to the GET request. So the only thing that the user sees in the URL is the key, not the message.

+3
source

You need to show the warning using Javascript on another page.

You probably want to pass the warning text in the request.

0
source

Source: https://habr.com/ru/post/1432101/


All Articles