PHP GET and POST to store data on server
PHP Tutorial » PHP GET and POST to store data on server
What is $_ GET and $_ POST in PHP?In this lesson, we'll show you how to send data to the server and store using GET and POST methods.
Both methods transmit the information to the server differently, and each of them has different advantages and disadvantages, as described below.
PHP $_GET is a PHP super global variable used to collect data from a HTML form after submitting an HTML form with method="get".
$_GET can collect data sent in the URL.
PHP $_POST is a PHP super global variable used to collect data form a HTML form after submitting an HTML form with method="post".
$_POST is widely used to pass variables.
The $_GET Method
Information sent from an HTML form using $_GET method it is visible to everyone in browser's address bar, what means that all the variable names and their values will be displayed in the URL
For a better understanding we present an example:
<?php
if( $_GET["name"] || $_GET["email"] ) {
echo "Welcome ". $_GET['name']. ". <br />";
echo "Your email is ". $_GET['email']. " .";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "GET">
<p> Name: <input type = "text" name = "name" /></p>
<p>Age: <input type = "text" name = "email" /></p>
<input type = "submit" />
</form>
</body>
</html>
Related subjects:
PHP Function
PHP $_GET and $_POST
PHP Array
Tags: PHP GET and POST to store data on server,
PHP GET and POST method diference, on same page, same time, variables, together, php form get and post,
What is difference between GET and POST in PHP?
What is $_ GET and $_ POST in PHP?
What is $_ POST and $_ GET?
What is diff between GET and POST method?
php post
php get url
php get all post data
php get request
php post to url
get and post method difference
get and post method in html examples
The $_POST Method
The $_POST method transfers information data via HTTP headers. The information is encoded.
The example below shows a form with an input field and a submit button.
When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag
<?php
if( $_POST["name"] || $_POST["age"] ) {
if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
die ("invalid name and name should be alpha");
}
echo "Welcome ". $_POST['name']. "<br />";
echo "Your email ". $_POST['email']. ".";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "email" />
<input type = "submit" />
</form>
</body>
</html>
Advantages of POST method
Advantages of POST method
- The POST method is useful for sending any sensitive information because is not visible to anyone.
- There is no limitation on size of data to be sent using the POST Method.
- Binary and ASCII data can be sent using POST method.
- Information sent using $_POST method goes through the HTTP header. By using HTTPS, you can ensure that your data is safe.
Disadvantages of POST Method
- POST requests do not cache.
- POST requests never remain in the browser history.
- It is not possible to bookmark the page because the variables are not displayed in URL.
PHP GET and POST to store data on server,
PHP GET and POST method diference, on same page, same time, variables, together, php form get and post,
What is difference between GET and POST in PHP?
What is $_ GET and $_ POST in PHP?
What is $_ POST and $_ GET?
What is diff between GET and POST method?
php post
php get url
php get all post data
php get request
php post to url
get and post method difference
get and post method in html examples
PHP GET and POST to store data on server - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
Find here examples of creative and unique website layouts.
Find here examples of creative and unique website CSS HTML menu.