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

PHP $_SERVER[‘SERVER_ADDR’] variable always returns 127.0.0.1

We have multiple load-balanced webserver machines running the same PHP webapp (LAMP) and I'd like to run slightly different code on each server (for testing purposes). I was hoping to use the $_SERVER['SERVER_ADDR'] super global to do something like…
Tom
  • 14,041
  • 16
  • 64
  • 80
3
votes
2 answers

How to detect multiple strings in $_SERVER["SERVER_NAME"]?

I would like to detect an array of strings in $_SERVER["SERVER_NAME"] to define a constant for environment like dev/prod. Basically, if localhost or .dev is in the URL, that would set the constant to "prod". Here is my try but I always got "prod"…
flks
  • 610
  • 10
  • 28
3
votes
4 answers

PHP Difference between Input::get() and $_GET[]

What is the difference between Input::get('value') and this: $_GET['value'] and when is better to use one of them?
Giorgi Khmaladze
  • 113
  • 1
  • 2
  • 11
3
votes
1 answer

PHP 5.4-specific ISSET query regarding $_GET. $_POST Superglobals

I have to upgrade a mission-critical (aren't they all?) Ubuntu server from PHP 5.3 to 5.4, and am happy about all but 1 possible problem. Our PHP scripts include around 1200 ISSET() references, nearly all of which check the status of either $_GET or…
Noseve
  • 33
  • 2
3
votes
10 answers

PHP: transfer a large array between two sites

I'm trying to transfer a large array between two sites in PHP. I'm the admin in both. The array is created on one site, and after its creation I wish to automatically redirect the user to the other site, and pass the processed array along. I cannot…
3
votes
1 answer

Global variable not updating inside static Class method in PHP

I have a problem with global variables in PHP. My problem is that a global variable that I change inside a static class method isn't updating outside the method. I've included the code: test.php define( 'APP_ID', 'TESTING' ); $_APP = array( 'test'…
GarbageGigo
  • 303
  • 2
  • 10
3
votes
2 answers

Create own $_SESSION-like variable?

This is me being a bit nitpicky, but I really like the ease in which $_SESSION works. So I was wondering if there is a way for me to make my rows in a database work like that. It was easy for me to make a superglobal, so for example…
user2178640
  • 95
  • 2
  • 8
3
votes
4 answers

Stop PHP from creating arrays in $_POST superglobal

PHP will automatically convert into $_POST['foo'] = array( 0 => 'x', 1 => 'y' ); Which is what you want most of the time. However, in this case I…
cdmckay
  • 31,832
  • 25
  • 83
  • 114
2
votes
1 answer

Store my own super global variable within PHP files?

I am building a website that will have hundreds of pages. Each of these pages will have a title, like: The Best Webpage in the world - Stackoverflow As above every page will have the sites name following the page title. I want store the sites name…
jamjam
  • 3,171
  • 7
  • 34
  • 39
2
votes
6 answers

Checking if a $_COOKIE value is empty or not

I assign a cookie to a variable: $user_cookie = $_COOKIE["user"]; How can I check if the $user_cookie received some value or not? Should I use if (empty($user_cookie)) or something else?
sunjie
  • 2,023
  • 7
  • 28
  • 28
2
votes
4 answers

PHP Session Id in $_COOKIES superglobal stays the same after destroy

Hy I am new to php and trying to destroy a session according to the php documentation here: http://php.net/manual/en/function.session-destroy.php so I am using this code:
Deli Sandor
  • 151
  • 1
  • 10
2
votes
1 answer

PHP builtin server/routing script: Empty superglobals

I'm trying to start a local server that catches all Urls called. Basically I want to simulate a REST-Interface for testing purposes, and write all Urls and the POST/PUT/PATCH Data to a file. I start the server like this: php -S localhost:9999 -t…
Fels
  • 1,214
  • 2
  • 13
  • 27
2
votes
6 answers

variable variables within $_POST and associative arrays

I'm probably being a little thick, but I can't seem to find an answer to this one. I'm moving from a server with register globals ON to one with it being off. It's a good thing, but unfortunately I have been used to years and years working with…
iagdotme
  • 1,033
  • 2
  • 21
  • 38
2
votes
4 answers

How to grab URL parameters using PHP?

I'm trying to grab each URL parameter and display them from first to last, but I want to be able to display any of the parameters anywhere on the page. How can I do this? What do I have to add or modify on my script? Here is an example of a URL…
synonyms
  • 59
  • 1
  • 1
  • 4
2
votes
1 answer

INPUT_SERVER returns null

I got weird results when I try to use filter_input with INPUT_SERVER (I am using PHP 5.6.9). I run this code: var_dump($_SERVER); foreach (array_keys($_SERVER) as $varkey) { var_dump($varkey, filter_input(INPUT_SERVER, $varkey)); } I get that…
nrofis
  • 8,975
  • 14
  • 58
  • 113
1 2
3
15 16