Tutorial for $_POST in Super Global Variables

What is $_POST?

It’s a global variable that’s used to collect data from the HTML form after it’s been submitted. Because the data is not accessible in the query string when a form uses method post to transfer data, security standards are maintained in this manner.

Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to the file itself in this case. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_POST:

Output:-

Before filling Data.
Just filling some data
After clicking on Submit button

We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables. We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables.

Tagged : / / / / / / / / / /

Tutorial for $_REQUEST in Super Global Variables

What is $_REQUEST?

$_REQUEST is a super global variable that’s used to collect data when an HTML form is submitted. Because $_POST and $_GET accomplish the same purpose and are extensively used, $_REQUEST is rarely used.

Global Variables - Superglobals Several predefined variables in PHP are  "superglobals", which means that they are always accessible, regardless of  scope. - ppt download

Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to this file in our example. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_REQUEST:

Output:-

Empty box
Just fill some data
After Clicking on submit button it shows this result

We’ve constructed a form in the above code that accepts the user’s name as input and prints it when the submit button is pressed. Because we alter the data on the same page using PHP code, we transfer the data received in the form to the same page using the $_SERVER[‘PHP SELF’] element as stated in the action attribute. The $_REQUEST super global array variable is used to obtain the data.

Tagged : / / / / / / / / / /

Tutorial for $_SERVER in Super Global Variables

What is $_SERVER?

It’s a super global variable in PHP that keeps track of headers, paths, and script locations. Some of these components are used to obtain data from the $_SERVER super global variables.

Server IP (PHP $_SERVER variables) | Drupal.org

Example:-

Output:-

To retrieve some information, we used the $_SERVER components in the code above. Using the ‘PHP SELF’ element, we retrieve the current file name that is being worked on. Then, using the ‘SERVER NAME’ attribute, we retrieve the current server name. Then we use ‘HTTP HOST’ to retrieve the host name.

The following table lists the most important elements that can go inside $_SERVER:

Element/CodeDescription
$_SERVER[‘PHP_SELF’]Returns the filename of the currently executing script
$_SERVER[‘GATEWAY_INTERFACE’]Returns the version of the Common Gateway Interface (CGI) the server is using
$_SERVER[‘SERVER_ADDR’]Returns the IP address of the host server
$_SERVER[‘SERVER_NAME’]Returns the name of the host server (such as www.w3schools.com)
$_SERVER[‘SERVER_SOFTWARE’]Returns the server identification string (such as Apache/2.2.24)
$_SERVER[‘SERVER_PROTOCOL’]Returns the name and revision of the information protocol (such as HTTP/1.1)
$_SERVER[‘REQUEST_METHOD’]Returns the request method used to access the page (such as POST)
$_SERVER[‘REQUEST_TIME’]Returns the timestamp of the start of the request (such as 1377687496)
$_SERVER[‘QUERY_STRING’]Returns the query string if the page is accessed via a query string
$_SERVER[‘HTTP_ACCEPT’]Returns the Accept header from the current request
$_SERVER[‘HTTP_ACCEPT_CHARSET’]Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1)
$_SERVER[‘HTTP_HOST’]Returns the Host header from the current request
$_SERVER[‘HTTP_REFERER’]Returns the complete URL of the current page (not reliable because not all user-agents support it)
$_SERVER[‘HTTPS’]Is the script queried through a secure HTTP protocol
$_SERVER[‘REMOTE_ADDR’]Returns the IP address from where the user is viewing the current page
$_SERVER[‘REMOTE_HOST’]Returns the Host name from where the user is viewing the current page
$_SERVER[‘REMOTE_PORT’]Returns the port being used on the user’s machine to communicate with the web server
$_SERVER[‘SCRIPT_FILENAME’]Returns the absolute pathname of the currently executing script
$_SERVER[‘SERVER_ADMIN’]Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host) (such as someone@w3schools.com)
$_SERVER[‘SERVER_PORT’]Returns the port on the server machine being used by the web server for communication (such as 80)
$_SERVER[‘SERVER_SIGNATURE’]Returns the server version and virtual host name which are added to server-generated pages
$_SERVER[‘PATH_TRANSLATED’]Returns the file system based path to the current script
$_SERVER[‘SCRIPT_NAME’]Returns the path of the current script
$_SERVER[‘SCRIPT_URI’]Returns the URI of the current page
Tagged : / / / / / / / / / /

Tutorial for $GLOBALS in Super Global Variables

What is $GLOBALS?

$GLOBALS is a super global variable that may be accessed from anywhere in the PHP script. All global variables are stored in the array $GLOBALS[], where index is the global variable name that may be retrieved.

All global variables are stored in an array named $GLOBALS[index] in PHP. The variable’s name is stored in the index.

Global Variables - Superglobals Several predefined variables in PHP are  "superglobals", which means that they are always accessible, regardless of  scope. - ppt download

The example below shows how to use the super global variable $GLOBALS:

Example:-

Output:-

Two global variables, $x and $y, are declared in the above code and are given a value. Then, in the GLOBAL array, a function multiplication() is written to multiply the values of $x and $y and store the result in another variable $z.

Tagged : / / / / / / / / / /

Tutorial for Super Global Variables in PHP

What is Super Global Variables in PHP?

These are PHP array variables with specific definitions that make it simple to retrieve information about a request or its context. The super global variables may be found all across your script. These variables can be accessible from any function, class, or file without the need to do any further steps, such as defining a global variable. They are mostly employed in applications to save and retrieve data from one page to the next.

PHP Variables and scopes

The following are the PHP superglobal variables:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
PHP 5 Global Variables - Superglobals - MEGATEK ICT ACADEMY
Tagged : / / / / / / /