Three methods for PHP to obtain form data

Source: Internet
Author: User

The following are three methods for obtaining form data in PHP:

Form partCode:

<Form name = "form1" method = "Post" Action = "">

<Input type = "text" name = "username">

<Input type = "Submit" name = "Submit" value = "Submit">

</Form>

Get form:

<? PHP

Echo ($ http_post_vars ["username"]);

Echo ($ _ request ["username"]);

Echo ($ username );

?>

Method 1 is a common method in versions earlier than 4.0, regardless of how register_globals is set;

Method 2 is a common method in version 4.2 and later, regardless of how register_globals is set;

Method 3 is applicable when register_globals = on is set in PHP. ini.

Supplement:

The content in the $ _ request is actually from $ _ get $ _ post $ _ cookie. The disadvantage is that the variable cannot be determined whether it comes from get post or cookie. It is not applicable to scenarios with strict requirements.

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.