Home > Backend Development > PHP Problem > How to jump to the page and pass value in php?

How to jump to the page and pass value in php?

coldplay.xixi
Release: 2023-03-03 06:48:01
Original
3851 people have browsed it

php method to jump to the page and pass the value: 1. POST value passing method, used for html [

] form jumping method; 2. GET value passing method, jumping on the page When the user logs in, follow the url to jump; 3. SESSION value transfer method is often used to save common data such as user ID after the user logs in.

How to jump to the page and pass value in php?

How to jump to the page and pass the value in php:

1. POST pass the value

Post value is a method used for html form jump, which is very convenient to use. For example: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"> &lt;html&gt; &lt;form action=&amp;#39;&amp;#39; method=&amp;#39;&amp;#39;&gt; &lt;input type=&amp;#39;text&amp;#39; name=&amp;#39;name1&amp;#39;&gt; &lt;input type=&amp;#39;hidden&amp;#39; name=&amp;#39;name2&amp;#39; value=&amp;#39;value&amp;#39;&gt; &lt;input type=&amp;#39;submit&amp;#39; value=&amp;#39;提交&amp;#39;&gt; &lt;/form&gt; &lt;/html&gt;</pre><div class="contentsignin">Copy after login</div></div> The action in the form is filled in with the url path of the jump page, and the method is filled in with the post method. After the submit button in the form is pressed, all the content with name in the form will be transferred to the filled in URL, which can be obtained through

$_POST['name']

, for example: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;?php $a=$_POST[&amp;#39;name1&amp;#39;]; $b=$_POST[&amp;#39;name2&amp;#39;]; ?&gt;</pre><div class="contentsignin">Copy after login</div></div> There is a very convenient trick here. When selecting type as 'hidden' in the input tag, the input tag will be hidden and will not be displayed on the page. However, the input tag is in the form and has a name value and The value value will also be passed along with the submit button. This hidden label can pass some content that you do not want to display.

2. GET value transfer

GET transfer value is passed by following the url. When the page jumps, it jumps with the url. Commonly used in the use of

tags. For example: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;a href=&amp;#39;delete.php?id=value&amp;#39;&gt;点我跳转&lt;/a&gt;</pre><div class="contentsignin">Copy after login</div></div>After jumping to

xxx.php

, you can get the passed value through $_GET['id']. The GET method is often used in URLs to delete or read a php file with a certain ID.

3. SESSION passing value

SESSION is a type of global variable, which is often used to save common data such as user ID after the user logs in. Once saved to SESSION, other pages can be obtained through SESSION. To use SESSION, you need to open the session:

<?php
//session赋值
   session_start();
   $_SESSION[&#39;one&#39;]=value1;
   $_SESSION[&#39;two&#39;]=value2;
 
//session值的读取:
   $one = $_SESSION[&#39;one&#39;];
    
   //session值的销毁
   unset($_SESSION[&#39;one&#39;]);
?>
Copy after login

Related learning recommendations:
PHP programming from entry to master

The above is the detailed content of How to jump to the page and pass value in php?. 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