“?”和GET方法之间的关系?

I was wondering what might be the relation between the question mark, the variable after the question mark ('show' in this case) and the way it is being passed to the GET method in PHP. Also, why don't we use POST instead of GET?

<?php 

    if (isset($_GET['show'])
       echo $_GET['show'];

?>
<input type="submit" onClick="window.location='index.php?
show=include.inc.php'">

Oh, and the file I am working on is index.php and upon a click, it shows the content of include.inc.php.

Please help. Sorry for any stupid questions.

The question mark denotes that there is a variable to follow!

The way that the $_GET function works is by passing the variables through the URL itself! In this case, its like putting up a sign that says "Hey, show is equal to include.inc.php".

$_POST does the same, but more discreetly. Instead of passing it through the URL, it creates a little package that travels to the receiver, similar to the postal system.

The code after the ? question mark is what is sent to the server in the HTTP request. (in the format: http://...URL...?key_1=value_1&key_2=value_2)

The onClick="..." code is javascript code executed when the user clicks that button in the browser.

window.location = ... is javascript code to force the browser to change the URL page to whatever it is assigned.

You can use POST instead of GET the data being sent to the server won't be as easily seen by the user in the browser, it won't become part of the URL. E.g. user can bookmark URLs with GET but not with POST data.

I was wondering what might be the relation between the question mark, the variable after the question mark ('show' in this case) and the way it is being passed to the GET method in PHP.

The question mark indicates the start of a query string in a URL.

The URL is the only convenient place to put data in an HTTP GET request because there is no request body. An HTML form will, by default, when submitted, trigger a GET request and encode the content of the form in the query string.

PHP puts data from the query string in $_GET. It does this no matter what the HTTP request method actually was. It is a poorly named variable name ($_QUERY would be better).

why don't we use POST instead of GET?

You can't bookmark or link to a POST request.

Refreshing the page after making a POST request will prompt the browser to ask the user if they really want to resubmit the data.

In short: POST is designed for making requests which change data on the server (which don't generally make sense to repeat). GET is designed for making requests which only get data from the server (and are thus repeatable).