php method to use post to jump to the page: first define the post processing page url; then get the url of the current page and parse the url; then get the parameter part in the url and parse the querycan parameter into the array variable; finally Loop to splice the form items, construct the form and jump.

How to use POST to jump to the page:
Everyone knows that PHP can use header('Location') Implement get request jump.
php can use curl to simulate post requests.
But I can’t find a ready-made PHP implementation of post jump.
Then the question is, if there is such a need, how to realize it?
Here today, I will share with you a PHP post jump method using form js.
index.php(initiate jump page)
<?php
//定义post处理页面url
$actionUrl = './action.php' ;
//获取当前页面的url
$url = 'http://' . $_SERVER [ 'HTTP_HOST' ]. $_SERVER [ 'PHP_SELF' ]. '?' . $_SERVER [ 'QUERY_STRING' ];
//解析url
$parseInfo = parse_url ( $url );
//获取url中的参数部分
$queryString = $parseInfo [ 'query' ];
//将querycan参数解析到数组变量
$queryArr =[];
parse_str ( $queryString , $queryArr );
//循环拼接表单项
$formItemString = '' ;
foreach ( $queryArr as $key => $value ){
$formItemString .= "<input name='{$key}' type='text' value='{$value}'/>" ;
}
//构造表单并跳转
$content =<<<EOF
<form style= 'display:none' name= 'submit_form' id= 'submit_form' action= '{$actionUrl}' method= 'post' >
{ $formItemString }
</form>
<script type= "text/javascript" >
document.submit_form.submit();
</script>
EOF;
exit ( $content );action.php(jump target page)
<?php //打印post接收到的数据 echo print_r( $_POST ,true);
If you want to learn more about programming, please contact us Pay attention to the php training column!
The above is the detailed content of How to use post to jump to the page in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor






