Applying and exploring predefined PHP arrays

Predefined arrays in PHP what are they?

  • Pre-prepared scripts for common functions within PHP such as getting and posting data
  • You do not see the code behind them – you just need to know they are there
  • You use them in exactly the same way as any custom array or variable you have created

php.net has a good example of some common predefined arrays

Source: http://php.net/manual/en/reserved.variables.php

The most common ones you are likely to come across are:

$_POST = Used for posting form data
$_GET = Used for retrieving data from a URL
$_REQUEST = Can accept data either via GET or POST 
$_SERVER = Stores info about server location
$_SESSION = Sessions are often used for persisting data during a user session
$_COOKIE = Used for storing data in key value pairs and stored in the client (browser)

Some quick tips on $_GET, $_POST and $_REQUEST

  • Use $_GET for short strings of data which do not carry sensitive info such as passwords
  • Use $_POST for large amounts of data such as forms and for sensitive information
  • Use $_REQUEST when you do not know or have any preference for how data is to be received by the application
No Comments

Post a Comment