$_POST is a reserved "superglobal" variable, meaning it is:
- Created automatically by the server and
- Available everywhere.
It automatically contains all data sent to the server with an HTTP POST request. Technically, it is (from the manual):
An associative array of variables passed to the current script via the HTTP POST method.
So if you have a form with name and email input fields, $_POST is an array with keys named name and email, which contain the data submitted by the user. You could access these with $_POST['name'] and $_POST['email'], respectively.
There are several other superglobal variables, namely:
$GLOBALS$_SERVER$_GET$_POST$_FILES$_COOKIE$_SESSION$_REQUEST$_ENV
You can learn much more about this by reading the manual entry on $_POST or the manual entry on superglobal variables.
To answer your other questions:
trim() removes white space (like spaces, tabs, and new lines) from the beginning and end of a string. For example, trim(' foo ') produces just foo without the spaces. You can also make it remove other characters. Say you have xxxfooxxx. trim('xxxfooxxx', 'x') will take away the xs and leave you just foo.
stripslashes() removes slashes from a string that has escaped characters. For example (from the manual):
$str = "Is your name O\'reilly?";
// Outputs: Is your name O'reilly?
echo stripslashes($str);
htmlspecialchars() turns special characters into HTML "entities." Specifically, it changes the following:
&(ampersand) becomes&"(double quote) becomes"whenENT_NOQUOTESis not set.'(single quote) becomes'(or') only whenENT_QUOTESis set.<(less than) becomes<>(greater than) becomes>
$_POST is part of the "superglobal" family.
I quote from the manual:
Superglobals are built-in variables that are always available in all scopes.
Several predefined variables in PHP are "superglobals", which means they are available in all scopes throughout a script. There is no need to do
global $variable; to access them within functions or methods.These superglobal variables are:
$GLOBALS$_SERVER$_GET$_POST$_FILES$_COOKIE$_SESSION$_REQUEST$_ENV
Then in your PHP handler, the form's element would be accessed in this fashion:
A basic example:
<?php
$name = $_POST['name']; // taken from <input type="text" name="name">
echo $name; // would echo the entered name from the form.
Something important to remember:
When using superglobals, they must be in uppercase letters.
$_post and $_Post for example are considered invalid. Use $_POST < exactly like this etc.
Some have/do that mistake, and will not work if not using the proper syntax (uppercase).
Also, the underscore _ between the $ and the superglobal name POST for example, is also required. $POST < being invalid. Again, use $_POST - $_GET - $_REQUEST etc.
About certain functions and predefined variables
trim()- Strips whitespace (or other characters) from the beginning and end of a string
stripslashes()- Un-quotes a quoted string
htmlspecialchars()- Converts special characters to HTML entities
$_SERVER["PHP_SELF"]- Executes from the same location of the originating script. Using
action=""does the same job.
- Executes from the same location of the originating script. Using
$_SERVER["REQUEST_METHOD"]- Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'
Eventual/potential database work
Should you later want to adventure yourself in databases, you could use these variables as shown below, using mysqli_* as an example:
<?php
// DB connection credentials
$name = mysqli_real_escape_string($con,$_POST['name']);
// rest of DB query
//
$con being something to the effect of:
$con = new mysqli("host","username", "password", "database");