+ 2
$_GET and $POST
Why we use $_GET and $POST variable?
4 Antworten
+ 4
"The PHP superglobals $_GET and $_POST are used to collect form-data."
Source: https://www.w3schools.com/php/php_forms.asp
+ 2
This is easier to understand when you have perspective. In web development we have different levels in order to make things easier to understand.
You have the front end working with html, js and css. This is called the front end and it provides an interface for a user to interact with and extract information from.
Then you have the backend which is running a server such as apache, IIS, node ect. So your quesion falls in this level and specifically php.
The way the front and back end communicates is through the use of a protocol called http. Http has a few commands two of them are GET and POST.
The get command is used by the browser to request a resource using a uri (universal resource identifier ) . The post command is used by the browser to send information to the server.
+ 2
So sometimes we want to send data to the site but the browser won't start talking to a server with a posi it starts talking using a get. Thats when we use a query string. The query string is the last part of a uri that starts with a question mark. ex: www.sololearn.com/app.php?app=test
Now I can write an app.php file that when someone requests app.php with an app variable in the query I can load that app for them.
$_GET ['app'] well return 'test'.
If I create app.php so that it returns all your apps and then have you select one with a form and set the form method to post. Then I can post the selected app to the app.php script. Then to retrieve the selected app I can use the $_POST to get the app.
ex:
<form method="post">
<select id="app">
<option value="test">
Test
</option>
</select>
<button type="submit">submit </button>
</form>
$_POST ['app']
So why use post instead of get you are probably thinking. Post provides more security and more data. You dont want to upload a picure with a query string using a get. You don't want someone's username and password visible in the url bar of the browser. Post is by default only allowed if you are sending it from that page so I cannot make a post from my site to your site unless you allow that to happen. I can however use a query string from my site to your site so you can use $_GET for public info like a link to a person's profile on fb or a youtube video but use post for uploading a profile picture, logging into Facebook or uploading a youtube video.
0
server side and browser side. read up on it. good question!