Php $ _ POST [] method for obtaining form data

Source: Internet
Author: User
Tags php tutorial set cookie setcookie

There is a dedicated command for getting form data in the php Tutorial. $ _ POST [] is the function. Below is a simple example.

<? Php
Echo 'hello, '. $ _ POST ['first _ name'].'! ';
?>
 
The output is the value of first_name from the form.

A little more complex instance,

$ _ POST ['name'] = trim ($ _ POST ['name']);

If (strlen ($ _ POST ['name']) = 0 ){
$ Errors [] = "Your name is required .";
}

Now, let's make a complete example of $ _ POST.

<? Php
$ User = $ _ POST ['user'];
$ Color = $ _ POST ['color'];
$ Self = $ _ SERVER ['php _ SELF '];

If ($ user! = Null) and ($ color! = Null ))
  {
Setcookie ("firstname", $ user, time () + 36000 );
Setcookie ("fontcolor", $ color, time () + 36000 );
Header ("Location: getcookie. php ");
Exit ();
  }
?>

 

<Html>

<Head>
<Title> Set Cookie Data </title>
</Head>

<Body>

<Form action = "<? Php echo ($ self);?> "Method =" post ">

Please enter your first name:
<Input type = "text" name = "user"> <br>

Please choose your favorite font color: <br>
<Input type = "radio" name = "color" value = "# FF0000"> Red
<Input type = "radio" name = "color" value = "#00FF00"> Green
<Input type = "radio" name = "color" value = "# 0000FF"> Blue
<Br>
<Input type = "submit" value = "submit">
</Form>

</Body>

</Html>


 
Conclusion: the above instance does not perform security processing, but simply obtains the data submitted in the form. We can perform security processing, such as isset () addslashes.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.