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
1
vote
0 answers

Is it possible in php to set super globals to a linked list data structure?

Is it possible in php to set super globals to a linked list data structure? Kinda like: $_GET = (SplDoublyLinkedList)$_GET; $_GET->setIteratorMode( SplDoublyLinkedList::IT_MODE_DELETE ); I can manually create a linked list and put them into it. I…
943A
  • 166
  • 8
1
vote
1 answer

What is the benefit of using the super global `$_SERVER['PHP_SELF']` in PHP?

What is the benefit of using the super global $_SERVER['PHP_SELF']?
proyb2
  • 19
  • 3
1
vote
1 answer

Use variable variables with PHP's Superglobal arrays outside of function and class

I'm beginner of PHP, I found a Warning says: Please note that variable variables cannot be used with PHP's Superglobal arrays within functions or class methods. So, does it mean I can use variable variables with Superglobal outside of function and…
LIU YUE
  • 1,593
  • 11
  • 19
1
vote
1 answer

Superglobals and htmlentities

I was reading about Superglobals and security. As a “rule”, I use htmlentities() for all the inputs and similar and for $_SERVER['HTTP_REFERER']; $_SERVER["REQUEST_METHOD"]; $_POST['thename']; $_GET['thename']; But since I am a novice I don´t…
Peter
  • 2,004
  • 2
  • 24
  • 57
1
vote
1 answer

PHP restrict access to superglobals or move the variable data

The dilemma comes from a plugin system that we are trying to implement security procedures that restrict the plugin to use only the data our system passes to it. The concern comes from passwords or other sensitive data that may be present in $_POST…
Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
1
vote
1 answer

Access files posted through AJAX using $_FILES variable

Trying to learn how to use the new AJAX file uploading, instead of using iframes or the good old PHP only file uploading. I understand how XHR requests work and have been using jQuery's $.post for a long time. But I can't get this one. The reason:…
Joshua
  • 17
  • 1
  • 6
1
vote
1 answer

PHPBB3and super globals?

I try to customize my PHPBB3 interface. For that I need to include a header and a footer. The header file I try to include has the use of... $this->_agent = $_SERVER['HTTP_USER_AGENT']; ...wrapped in a function. Here is the error message when I open…
Baylock
  • 1,246
  • 4
  • 25
  • 49
1
vote
4 answers

Reusing a mysql connection in oop php

Solution taken from comment so I can't accept an answer for this to be closed. But I did post the actual solution that works for me below I'm new to OOP and I just can't figure out, even after reading through quite few examples, how use the same…
1
vote
1 answer

Define global constant in Matlab

I want to define SI global prefixes in Matlab to make my code self explaining. I defined it in startup.m: % define SI prefix global SI SI.milli = 1e-3; SI.micro = 1e-6; % and so on.. It works fine, if I run test.m directly % test.m file Area = 10…
Jonas Stein
  • 6,826
  • 7
  • 40
  • 72
1
vote
1 answer

How do PHP session IDs work?

I'm a little confused on what session ID's in PHP actually are, and what they are useful for. I am coding a website with user information, register, and login. In login script tutorials in PHP, many people include session_start(). They also check…
Sojourn
  • 41
  • 5
1
vote
2 answers

Overcoming Warning in NetBeans - PHP - Do not use Superglobals Array directly $_GET

I have some lines of code like this; A. if ( isset($_GET["logout"]) && $_GET["logout"] == 1){ do_something; } I replace with ( to get rid of the warning) ; B. if ( isset( filter_input(INPUT_GET,'logout',FILTER_SANITIZE_NUMBER_INT) …
MarcoZen
  • 1,556
  • 22
  • 27
1
vote
1 answer

Wrap superglobal $_GET inside a class property

The goal is to get some precise values of $_GET in a property of a class while: removing any key not desired defaulting values when keys are not defined With this code in a file /request.php: $req = new request(); var_dump($req); class request { …
1
vote
1 answer

Get page referer and missing page that generates Error 404 using PHP

I've been researching online for a way to retrieve the URL that generates a 404 error. I've found various postings on this subject in this and other sites and tried them all. Unfortunately I'm still not being able to get what I want. I will try to…
Dentra Andres
  • 371
  • 1
  • 7
  • 18
1
vote
2 answers

Textarea Cutoff in PHP $_POST array

My textarea on a webform [using POST method] is getting cutting off at 1024 characters. The field does not have a max length attribute set and will allow over 1024 characters to be entered. However, when I view the $_POST array in Eclipse and try…
Trevor.Screws
  • 541
  • 6
  • 18
1
vote
1 answer

Is it possible for $_SERVER['SCRIPT_FILENAME'] to not be set?

Hey everyone, some background info: In the config file for my website, I set the mysql database name, username and password based on the contents of $_SERVER['HTTP_HOST']. Because it is possible for this variable to not be set in the case of old…
Aistina
  • 12,435
  • 13
  • 69
  • 89