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

A list of operators on Eloquent's where() method

How to have a whitelist of IP addresses that can access files in .htaccess

How to return an item in Eloquent, or throw a ModelNotFoundException exception if it isn't found?

How to force gzip compression in Apache with .htaccess

What are the main error types in PHP

How to access the Laravel's route parameters outside of the controller?

How to split a string into an array, in JS

How to create random numbers in JS?

Point all requests to one PHP file

How to return JSON data to the user in Laravel?