Three common methods for transferring values from PHP to different pages and passing values between php and html

Source: Internet
Author: User
This article mainly introduces three common methods for transferring values from PHP to different pages, as well as related information on transferring values between php and html. For more information, see

This article mainly introduces three common methods for transferring values from PHP to different pages, as well as related information on transferring values between php and html. For more information, see

In project development, we often see the transfer of different pages in the web work. This article lists three common methods.

I have been in contact with PHP for a few months. This article summarizes three different page passing methods that are commonly used in programming. I hope you can refer to them. I hope you can discuss any comments together.

I. POST value transfer

Post value is used for html

In form, enter the url path of the page to jump to, and in method, enter the post method. After you press the submit button in the form, all the content with name in the form will be uploaded to the filled url, which can be obtained through $ _ POST ['name']. For example:

<? Php $ a =$ _ POST ['name1']; $ B =$ _ POST ['name2'];?>

Here is a handy tip. When you select "type" as "hidden" in the input tag, the input tag is hidden and not displayed on the page, but the input tag is in form, and there are name and value values, which will also be passed along with the submit button. This hidden tag can pass some content that you do not want to display.

2. GET value transfer

The GET value is transmitted by following the url. When the page jumps, the value is redirected to the url. It is often used for labels. For example:

Click to jump

After you jump to xxx. php, you can GET the passed value through $ _ GET ['id. The GET method is commonly used in URLs to delete or read PHP files of an id.

Iii. SESSION value transfer

SESSION is a type of global variables and is often used to save frequently used data such as user IDs after users log on. Once saved to the SESSION, other pages can be obtained through the SESSION. To use the SESSION, enable the session:

<? Php // session value: session_start (); $ _ SESSION ['one'] = value1; $ _ SESSION ['two'] = value2; // read session values: $ one = $ _ SESSION ['one']; // destroy the unset of the session value ($ _ SESSION ['one']);?>

The preceding three methods are provided for your reference and I hope you will like them.

Passing values between php and html

How can I use form to pass values to php? How can php receive such data?

------ Solution ----------------------

Two Parameters in the form, one action, indicates the file to which the data is transmitted. If this parameter is left blank, the default parameter is used. One method indicates the method used for data transfer. There are two types: get and post.

Add name to the input box

The accepted files are received in $ _ POST or $ _ GET. The simplest is to directly var_dump ($ _ POST) or var_dump ($ _ GET) and then you will know how to call it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.