Questions tagged [superglobals]

Superglobals are built-in variables that are always available in all scopes.

Superglobals are built-in variables that are always available in all scopes.

Several predefined variables in PHP are "superglobals", which means they are available in all scopes throughout a script. There is no need to do global $variable; to access them within functions or methods.

These superglobal variables are:

  • $GLOBALS
  • $_SERVER
  • $_GET
  • $_POST
  • $_FILES
  • $_COOKIE
  • $_SESSION
  • $_REQUEST
  • $_ENV

https://php.net/manual/en/language.variables.superglobals.php

235 questions
121
votes
5 answers

Warning "Do not Access Superglobal $_POST Array Directly" on Netbeans 7.4 for PHP

I've got this message warning on Netbeans 7.4 for PHP while I'm using $_POST, $_GET, $_SERVER, .... Do not Access Superglobal $_POST Array Directly What does it mean? What can I do to correct this warning? Edit: The Event sample code still shows…
Kannika
  • 2,538
  • 2
  • 27
  • 38
59
votes
3 answers

Possible Values For: PHP_OS

Is there a place to find a list of the possible values for the PHP predefined constant PHP_OS ? I'd like to use this value for a system requirements check, but need to know how different operating systems are named in this variable. Through some…
Wilco
  • 32,754
  • 49
  • 128
  • 160
11
votes
2 answers

$_SERVER['HTTP_HOST'] contains port number too =/

I don't know maybe it's a bug. I have 2 virutalhosts on my server. virtualhost1.com virtualhost2.com if i open virtualhost1.com with port 80 (virtualhost1.com:80) $_SERVER['HTTP_HOST']='virtualhost1.com'; but if i open…
dynamic
  • 46,985
  • 55
  • 154
  • 231
11
votes
2 answers

How to access superglobals in correct way?

I'm discovering secrets of PHP. I've found one thing that I don't have answer to. I would like to access variables from super-global $_SESSION in class. Everything works but PHPMD engine to check mess in code is showing me issue. I'm getting value…
UareBugged
  • 178
  • 1
  • 11
11
votes
2 answers

Is the web server variable $_SERVER['REMOTE_ADDR'] reliable?

I have generally assumed that in a PHP script I can test $_SERVER['REMOTE_ADDR'] to establish the IP address from which the request originated. However, I am starting to wonder if things are not a bit more complicated. Here is the scenario I run…
DroidOS
  • 8,530
  • 16
  • 99
  • 171
10
votes
7 answers

Should I Use PHP Superglobals or Filter Input to Retrieve $_GET data?

I really hate global variables - maybe its the C# programmer in me but when I'm working in PHP I grit my teeth every time I have to do something like this: $strUsername = $_GET['username']; Yes, I'm grossly oversimplifying it and yes yes I sanitize…
Jarrod Nettles
  • 6,193
  • 6
  • 28
  • 46
9
votes
6 answers

Is using superglobals directly good or bad in PHP?

So, I don't come from a huge PHP background—and I was wondering if in well formed code, one should use the 'superglobals' directly, e.g. in the middle of some function say $_SESSION['x'] = 'y'; or if, like I'd normally do with variables, it's better…
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
9
votes
1 answer

How is PHP's $_SERVER[REQUEST_TIME] set?

What happens on the server to set the request time? Does it take into account the timezone for which the server is configured? I'm asking because I need to know, if I have a site that has a timezone set as a site-wide variable, and I compare…
beth
  • 1,916
  • 4
  • 23
  • 39
8
votes
4 answers

Understanding the PHP $GLOBALS variable

I am learning PHP from w3schools' PHP Tutorial. While learning PHP I came across the concept of predefined global variables i.e. Superglobals. In a curiosity to understand "Superglobals" more deeply I wrote the following code and executed it in a…
PHPLover
  • 1
  • 51
  • 158
  • 311
8
votes
3 answers

What happens if you assign a value to $_REQUEST?

I recently came across this line in a PHP script: $_REQUEST['start_date']=$date; Is it allowed or useful in any way to assign something to the super global $_REQUEST variable? If there is a $_COOKIE['start_date'] will this change the cookie value? …
Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127
8
votes
1 answer

how safe is $_SERVER["HTTP_HOST"]?

I have a database full of website urls, the primary key is the $_SERVER["HTTP_HOST"] of the website. When a user navigates to ... lets say www.my-epic-example-url.com, It will connect the the database and use the $_SERVER["HTTP_HOST"] of that…
AlexMorley-Finch
  • 6,785
  • 15
  • 68
  • 103
7
votes
5 answers

Is there any way to dynamically access a superglobal?

As a web developer, I'm always using this approach to something like a login form or other “save” operation (ignoring the dangers of directly accessing input variables): if (isset($_POST['action']) && $_POST['action'] == 'login') { // we're…
Abraham Vegh
  • 1,490
  • 1
  • 12
  • 32
7
votes
3 answers

What is the value in '$_SERVER['UNIQUE_ID'] used for?

I can't find any mention of it in the documentation, but there seems to be an additional entry in the $_SERVER superglobal named UNIQUE_ID? What is this value used for? It's fairly obvious that it's a unique ID, but of what? Of the current session,…
IQAndreas
  • 8,060
  • 8
  • 39
  • 74
7
votes
10 answers

how to check multiple $_POST variable for existence using isset()?

I need to check if $_POST variables exist using single statement isset. if (isset$_POST['name'] && isset$_POST['number'] && isset$_POST['address'] && etc ....) is there any easy way to achieve this?
PHP
  • 159
  • 3
  • 3
  • 12
7
votes
3 answers

Getting $_GET parameters from route in Zend Framework 2

Zend Framework 1 had a very simple way of parsing URL routes and setting found params in the $_GET superglobal for easy access. Sure, you could use ->getParam($something) inside the controller, but if the param was found in the URL, it was also…
Swader
  • 11,387
  • 14
  • 50
  • 84
1
2 3
15 16