What are the predefined variables in PHP?

PHP: What are the predefined variables in PHP?

There are a handful of predefined variables in PHP. They include:

$GLOBALS — References all variables available in global scope

$_SERVER — Server and execution environment information

$_GET — HTTP GET variables

$_POST — HTTP POST variables

$_FILES — HTTP File Upload variables

$_REQUEST — HTTP Request variables

$_SESSION — Session variables

$_ENV — Environment variables

$_COOKIE — HTTP Cookies

$php_errormsg — The previous error message

$HTTP_RAW_POST_DATA — Raw POST data

$http_response_header — HTTP response headers

$argc — The number of arguments passed to script

$argv — Array of arguments passed to script

The most commonly used ones, in my opinion, are $_GET, $_POST, $_SERVER, $_FILES, $_SESSION and $_COOKIE (so, the majority of them!)

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about What are the predefined variables in PHP?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the PHP language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to get table column names from a database table in Eloquent?

How to check if an object or variable is an array, in JS?

How to find an item by Primary Key in Eloquent, or throw a ModelNotFoundException exception if it isn't found?

What is the max size, by default, of GET variables?

When is __destruct called in PHP?

How to hide certain file types from directory listings

How to exclude URLs from the Laravel CSRF protection?

Point all requests to one PHP file

How to Extract Query String (from a URL) Into an Associative Array in PHP

What are the main error types in PHP