Home > Backend Development > PHP Problem > How to jump to pass value in php header

How to jump to pass value in php header

藏色散人
Release: 2023-03-12 11:14:01
Original
2596 people have browsed it

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.

How to jump to pass value in php header

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");
Copy after login

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=&#39;fr&#39; action=&#39;{$url}&#39; method=&#39;POST&#39;>
    <input type=&#39;hidden&#39; name=&#39;field1&#39; value=&#39;{$field1}&#39;>
    <input type=&#39;hidden&#39; name=&#39;field2&#39; value=&#39;{$field2}&#39;>
</form>
<script type=&#39;text/javascript&#39;>
    document.fr.submit();
</script>
EOT;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template