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
2
votes
2 answers

Use variable variables with superglobal arrays

I wonder if is possible to read dynamically superglobal variables, I would like to do something like that:
onnynneji
  • 33
  • 3
2
votes
1 answer

Measuring the time of PHP scripts - Using $_SERVER['REQUEST_TIME']

Are this methods a reliable way to measure a script: $time = ($_SERVER['REQUEST_TIME_FLOAT'] - $_SERVER['REQUEST_TIME']); or $time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']); Which one should be used? And what's the difference of each…
Ash501
  • 321
  • 2
  • 4
  • 10
2
votes
2 answers

Why doesn't the $GLOBALS superglobal has an underscore?

Just for curiosity. All superglobals (for example $_POST, $_GET, $_FILES, $_SESSION) have an underscore and only the $GLOBALS superglobal does not. Why is that so? What does the underscore mean in superglobal variables in PHP and generaly in PHP?…
Branko Sego
  • 780
  • 6
  • 13
2
votes
4 answers

PHP's real SESSION object

EDIT: (UPDATED) Maybe my question was not clear enough. Ok, lets put it this way: $arr["a"] = 10; var_dump($arr); $arr["b"] =& $arr["a"]; var_dump($arr); the first var_dump returns: array 'a' => int 10 While the second one returns: array 'a'…
lepe
  • 24,677
  • 9
  • 99
  • 108
2
votes
3 answers

Using isset and filter_input the correct way in PHP

I am developing a basic API for some simple functionality. I am capturing inputs like below: if ($action == 'delete' && isset($_POST['targetId']) && isset($_POST['userId'])) { //The isset causes "Do not access Superglobal _POST array directly"…
iSee
  • 604
  • 1
  • 14
  • 31
2
votes
2 answers

Wrap superglobals in a class?

Should I just call them by their name $_GET, $_POST, $_SESSION //etc, or should I wrap them in a class? For example for the POST superglobal, so that it returns false if a certain array index is not set? Let's say I have a Validator class. So I have…
502 Error
  • 233
  • 2
  • 12
2
votes
7 answers

$_SERVER['document_root']?

is this pointing to the directory where the current file is executed?
ajsie
  • 77,632
  • 106
  • 276
  • 381
2
votes
3 answers

Unregistering Globals?

I'm having trouble understading this function. I know what register_globals is and how long it has been depreciated from PHP but I'm looking at this code and I'm like, what in the?...
Codist
  • 1,198
  • 2
  • 11
  • 28
2
votes
2 answers

Using isset or @ to test/assign a superglobal variable

Can I use @ instead of isset to assign or test superglobal variable ? Use this : $foo = intval(@$_POST['bar']); Instead of this : $foo = isset($_POST['bar']) ? intval($_POST['bar']) : 0; works without generate a notice but maybe for some reasons,…
Loïc G.
  • 3,087
  • 3
  • 24
  • 36
2
votes
1 answer

PHP: write in php://input

I would like to know how I could write something in "php://input". Actually I would like to know if I can use this stream like a superglobal. Example with $_POST file1: $_POST['param'] = "test"; file2: $param = $_POST['param']; What I want file1:…
Michaël
  • 1,120
  • 1
  • 15
  • 30
2
votes
3 answers

Why don't I see the request variable I set in the first script?

As I try to retrieve the variable status from the $_REQUEST[] array I set in the first script (and then do a redirect), I see nothing but a warning Undefined index: status. Why is that ?
saplingPro
  • 20,769
  • 53
  • 137
  • 195
2
votes
3 answers

Get full page URL with PHP

I am trying to get the entire page URL as a string in PHP - so, if the requested URL is ./foo.php?arg1=test&arg2=test2, I get "./foo.php?arg1=test&arg2=test2". I know that I can get the ./foo.php part from $_SERVER and the variables from $_GET, but…
benjy
  • 4,664
  • 7
  • 38
  • 43
2
votes
2 answers

Variable variables and superglobals

I'm transitioning a huge PHP software from PHP4 to PHP5 and among the many (many) problems I'm facing, the biggest one so far seems to be that the previous programmer just banqueted over the register_globals feature, throwing every now and then some…
goffreder
  • 503
  • 3
  • 17
1
vote
1 answer

Form action with parameters - parameters are not in $_GET or $_POST

I am working with re-implementing a REST API for which client has no source code and is losing access to server... I am finding the the caller is sending posts but without posted data. All of the parameters are specified in the URL or what would…
jerrygarciuh
  • 21,158
  • 26
  • 82
  • 139
1
vote
3 answers

$_REQUEST superarray not initialized in $GLOBALS array

PROBLEM So, I have this function to retrieve and proceed data from $_REQUEST, $_POST, $_GET or $_COOKIE arrays. I know which array to use only from function call. Simplified ex: function gg( $name, $type="_REQUEST" ) { return isset(…
meeDamian
  • 1,143
  • 2
  • 11
  • 24