WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP 5 Form Handling


The PHP superglobals $_GET and $_POST are utilized to gather structure data.


PHP - A Simple HTML Form

The model underneath presentations a basic HTML structure with two info fields and a submit button:

Example

<html>
<body>

<form action="login.php" method="post">
Name: <input type="text" name="name"><br>
Pass: <input type="text" name="pass"><br>
<input type="submit">
</form>

</body>
</html>

When the client rounds out the structure above and taps the submit catch, the structure information is sent for preparing to a PHP record named "login.php". The structure information is sent with the HTTP POST method.

To show the submitted information you could just reverberate every one of the factors. The "login.php" looks like this:

<html>
<body>

Welcome <?php reverberation $_POST["name"]; ?><br>
Your pass address is: <?php reverberation $_POST["pass"]; ?>

</body>
</html>

The yield could be something like this:

Welcome John
Your pass address is sdawe324#1

The same outcome could likewise be accomplished utilizing the HTTP GET method:

Example

<html>
<body>

<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
Pass: <input type="text" name="pass"><br>
<input type="submit">
</form>

</body>
</html>

and "welcome_get.php" looks like this:

<html>
<body>

Welcome <?php reverberation $_GET["name"]; ?><br>
Your pass address is: <?php reverberation $_GET["pass"]; ?>

</body>
</html>

The code above is very basic. Be that as it may, the most critical thing is absent. You need to approve structure information to shield your content from vindictive code.


GET versus POST

Both GET and POST make an exhibit (for example exhibit( key => esteem, key2 => value2, key3 => value3, ...)). This exhibit holds key/esteem sets, where keys are the names of the structure controls and qualities are the information from the user.

Both GET and POST are treated as $_GET and $_POST. These are superglobals, which implies that they are constantly open, paying little mind to scope - and you can get to them from any capacity, class or record without doing anything special.

$_GET is a variety of factors gone to the present content by means of the URL parameters.

$_POST is a variety of factors gone to the present content by means of the HTTP POST method.


When to utilize GET?

Information sent by means of a structure utilizing the GET technique is unmistakable to everybody (every single variable name and qualities are shown in the URL). GET additionally sets confines on the measure of data that can be sent - around 2000 characters.

because the factors are shown in the URL, it is conceivable to bookmark the page, which can be valuable in some situations.

GET ought to NEVER be utilized for sending passwords or other delicate data! When utilizing POST or GET, legitimate approval of structure information through separating and handling is crucially vital to shield your structure from programmers and exploits!

When to utilize POST?

The two techniques for submitting frames are GET and POST.

Information sent from a structure by means of the POST strategy is undetectable to other people, since all names and additionally values are installed inside the body of the HTTP ask. Likewise, there are no restrictions on the measure of data to be sent.

POST is the favored technique for sending structure information.