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

What is Agile software development?

What is an example of an object literal?

What is the loop variable in a @foreach loop in Blade?

How to add the CSRF (Cross-site request forgery) token in Laravel?

How to hide certain file types from directory listings

Is multiple inheritance supported in PHP?

Push vs Pop vs Shift vs Unshift

When is __destruct called in PHP?

How to see all of the options for an artisan command?

How to undelete a soft deleted Eloquent row?