Home > Backend Development > PHP Problem > How to implement post jump in php

How to implement post jump in php

藏色散人
Release: 2023-03-06 15:26:02
Original
3428 people have browsed it

php method to implement post jump: first define the post processing page url; then get the url of the current page; then parse the querycan parameter into an array variable; finally construct the form and jump.

How to implement post jump in php

Recommended: "PHP Video Tutorial"

php to achieve post jump

Do you agree? Know that PHP can use header('Location') to 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 = &#39;./action.php&#39; ;
 
//获取当前页面的url
$url = &#39;http://&#39; . $_SERVER [ &#39;HTTP_HOST&#39; ]. $_SERVER [ &#39;PHP_SELF&#39; ]. &#39;?&#39; . $_SERVER [ &#39;QUERY_STRING&#39; ];
 
//解析url
$parseInfo = parse_url ( $url );
 
//获取url中的参数部分
$queryString = $parseInfo [ &#39;query&#39; ];
 
//将querycan参数解析到数组变量
$queryArr =[];
parse_str ( $queryString , $queryArr );
 
//循环拼接表单项
$formItemString = &#39;&#39; ;
foreach ( $queryArr  as  $key => $value ){
     $formItemString .= "<input name=&#39;{$key}&#39; type=&#39;text&#39; value=&#39;{$value}&#39;/>" ;
}
 
//构造表单并跳转
$content =<<<EOF
<form style= &#39;display:none&#39;  name= &#39;submit_form&#39;  id= &#39;submit_form&#39;  action= &#39;{$actionUrl}&#39;  method= &#39;post&#39; >
{ $formItemString }
</form>
<script type= "text/javascript" >
document.submit_form.submit();
</script>
EOF;
 
exit ( $content );
Copy after login

action.php(jump target page)

<?php
//打印post接收到的数据
echo  print_r( $_POST ,true);
Copy after login

get visit:

http:/ /yoururl/index.php?name=jack&age=100&sex=boy&no=001

The truth is here! The post automatically jumps to the target page, and the post value can be obtained in the target page.

The above is the detailed content of How to implement post jump in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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