Ad

PHP $_POST Method

 


What is PHP  for $_POST

One of the common ways to communicate data from a client (such a web browser) to a server via HTTP is through the POST method. It is often used in web development and is specified by the HTTP protocol. This is especially true when interacting with forms and submitting data that must be processed or save. server.$_POST is one of the default variables or superglobal variables in PHP. It is a combination of key/value pairs passed to the URL via the HTTP POST method, using the URLEncoded or multipart/form-data format in the request.

Purpose :-

 Sending data to the server using POST requests is common for creating or updating server resources. For instance, the POST method is typically used to send data to the server when you submit a form on a website (such as to create a new account or leave a remark).

Data Transmission :-

In a POST request, data is transmitted in the HTTP request body as opposed to the GET method, which appends data to the URL. Because of this, it may be used to deliver bigger files or sensitive data that shouldn't be seen through the URL.

Security :- 

Sensitive data is better protected with the POST technique as it is not saved in the URL parameters, server logs, or browser history. It does not, however, encrypt the data by default; for safe transmission, other precautions such as HTTPS need be taken.

Implementation :-

When developing a website with PHP or any other server-side language, you respond to POST requests by gaining access to the client-sent data. For example, in PHP, the $_POST superglobal array contains data supplied via POST.

  Limitation :- 

The POST method is limited by the size of data that can be transferred to the server side. This limit may vary depending on server configuration and PHP settings (post_max_size in php.ini).


Example :-


HTML form  (save index.html):-
  input type  'first_name', 'last_name','address'
'
submits the data process_form.php use POST method ('method=post')

PHP 

 Checks form use POST($_SERVER["REQUEST_METHOD"]=="POST")
 Display submitted data PHP 'echo' statement

When you write the form in index.html and 

     click "Send", the data (first_name, last_name,   address) will be sent to process_form.php using the POST method. We collect information and show it to the user.

Source Code -


<html>
<body>

// html code create a form

   <form action="<?php echo $_SERVER
['PHP_SELF'];?>" method="POST">
      <p>First Name: <input type="text"
name="first_name"/> </p>
      <p>Last Name: <input type="text"
name="last_name" /></p>
      <p>Address : <input type="text"
name="address"></p>
      <input type="submit" value="Submit" />
   </form>

//php code post method
   
<?php
      echo "<h3>First Name: "
. $_POST['first_name'] . "<br /> " .
      "Last Name: " . $_POST['last_name']
."<br>"."Address:".$_POST['address']. "</h3>";
   ?>

</body>
</html>

OutPut :-






Related Post :-

php data type

html block and inline element

javascript do while loop

No comments

Powered by Blogger.