Home >Backend Development >PHP Tutorial >Three common ways to pass values ​​​​to different pages in PHP and problems in passing values ​​between php and html, phphtml_PHP tutorial

Three common ways to pass values ​​​​to different pages in PHP and problems in passing values ​​between php and html, phphtml_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:04:35926browse

Three common ways for PHP to transfer values ​​​​to different pages and the problem of value transfer between php and html. phphtml

In project development, we often see value transfer between different pages. In web work, this article lists three common methods for everyone.

I have been working with PHP for a few months. This article summarizes the three different page value transfer methods commonly used in the programming process during this period. I hope it can be a reference for everyone. If you have any opinions, I hope you can discuss them together.

1. POST value

Post value transfer is a method used for HTMLff9c23ada1bcecdd1a0fb5d5a0f18437 form jump, which is very convenient to use. For example:

 <html>
 <form action='' method=''>
 <input type='text' name='name1'>
 <input type='hidden' name='name2' value='value'>
 <input type='submit' value='提交'>
 </form>
 </html>

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:

<&#63;php
$a=$_POST['name1'];
$b=$_POST['name2'];
&#63;>

Here is a very convenient tip. 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 a value. The value will also be passed along with the submit button. This hidden label can pass some content that you don't want to display.

2. GET value

The value passed by GET is passed by following the url. When the page jumps, it will jump by following the url. Commonly used in the use of 3499910bf9dac5ae3c52d5ede7383485 tags. For example:

<a href='delete.php&#63;id=value'>点我跳转</a>

After jumping into 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 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:

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

The above are the three methods listed by the editor for your reference, and I hope you like them.

Value transfer problem between php and html

How do I use form to transfer values ​​to php for such a form? The key point is how php receives such data

------Solution Idea----------------------

There are two parameters in the form, one is action, which indicates which file to transfer to. If you don’t specify it, it will be passed to itself by default; one is method, which indicates how to transfer. There are two types: get and post

Add name to the input box

Use $_POST (post method) or $_GET (get method) to receive the accepted file. The simplest is to directly var_dump($_POST) or var_dump($_GET) and then you will know how to call it

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1073119.htmlTechArticleThree common ways for PHP to transfer values ​​​​to different pages and the problem of value transfer between php and html, phphtml is in the project In development, we often see value transfer between different pages in web work. This article lists it for everyone...
Statement:
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