How to implement header jump value transfer: 1. Create a PHP sample file and output an HTML page containing the form; 2. Submit the form through JS in the page to simulate Post jump.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to jump and pass value in php header?
PHP Header jumps and passes Post data
We sometimes need to make some links in PHP For jumps, the following method is often used:
header("Location: $url");
However, this method cannot satisfy the need to post data to the target link when jumping. One solution is to output an HTML page containing a form, and pass JS in the page The method of submitting the form simulates Post jump.
<?php echo <<<EOT <form name='fr' action='{$url}' method='POST'> <input type='hidden' name='field1' value='{$field1}'> <input type='hidden' name='field2' value='{$field2}'> </form> <script type='text/javascript'> document.fr.submit(); </script> EOT;
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to jump to pass value in php header. For more information, please follow other related articles on the PHP Chinese website!