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
1 answer

Where should I save the access token value shared by multiple sessions in php?

You are about to send an email using the outgoing email api. At this time, access_token only needs to be acquired once, so I want to run the authentication process once and share it in several sessions without renewing the key until the key expires.…
DuRu Kang
  • 23
  • 5
1
vote
1 answer

Superglobal GET using PHP

I am new to php and I couldn't find the answer on stack. I am experimenting and trying to figure out how I can use the superglobal GET to display an image and also change the *count depending on how the user modifies it in the URL. I would like to…
1
vote
4 answers

How to display an error when the uploaded files are exceeding post_max_size php?

How to display an error when the uploaded files are exceeding post_max_size php? print_r($_FILES); I get an empty array when I have exceeded the post_max_size array() I got this from php.net but I don't understand it and don't know how to do…
Run
  • 54,938
  • 169
  • 450
  • 748
1
vote
1 answer

What is the new proper way to pass a variable between Ajax code and a PHP file?

I am writing a login page for a web application. I am using ajax to pass a user name and pwd to a php file. In the php file I started with the following code. if(isset($_POST)) { $uname = $_POST['uname']; $pwd = $_POST['pwd']; } IntelliJ…
user9329083
1
vote
1 answer

A session variable doesn't get passed properly?

So, I am trying to set a $_SESSION variable and pass it to another page, but the variable on the other page is different than the one it must be. In petitionlist.php the $_SESSION['petitionNameT'] = $petitionName1; is being set. The contest of…
1
vote
2 answers

Problem with codeigniter's redirect function

This may be a n00b topic but, anyways, I have been having a rather difficult and strange time with this bug. Basically I was working on a controller method for a page that displays a form. Basically, I was debugging the form's submitted data by var…
racl101
  • 3,760
  • 4
  • 34
  • 33
1
vote
0 answers

How do certain aspects of superglobals work in relation to functions in PHP?

I am new to coding and this website, so I apologize in advance if I word my questions incorrectly or do not know the proper way of communicating. I have heard that using global variables is bad practice, but I am just eager to learn and understand…
1
vote
1 answer

Client access to Superglobals

PHP Superglobals behave in different ways and I'm never sure about which one to use. When can the client (I'm not talking about hackers or security attacks, but "normal users") edit, create or access a Superglobal variable? Even php.net…
user13327421
1
vote
3 answers

$_POST superglobal not passing (1and1)

I just made a basic form page and through Aptana, WAMP, and through a basic 1and1 hosted page, I cannot get the form fields to pass through the $_POST superglobal. Here is the index.html page:

Type in…

Jack Reed
  • 11
  • 1
1
vote
1 answer

What is the reason for overwriting super global $_FILES while uploading multiple files using code igniter

Assume post request is validated, and functional code is good enough and just an observation mostly multiple file uploading Code Igniter Sample code looks like this, Concern is why Super global variable like $_FILES is overwritten ? Is this a good…
1
vote
3 answers

Check if php script was called by the server or remotely in php?

I have a crontab php script that resides in one of the folders on abc.tld. The problem is that the script could also be fired by calling it directly (i.e. http://abc.tld/crontab.php) To eliminate such possibility, I assume, I could do something…
Pavel
  • 565
  • 6
  • 19
1
vote
1 answer

How does the function unset() behaves differently depending on the way to access a global variable inside the function?

As per my knowledge, any variable declared outside the function is treated as a 'Global Variable' in PHP. To access such global variable inside the function there are two ways one is to declare is as global inside the function with the keyword…
PHPLover
  • 1
  • 51
  • 158
  • 311
1
vote
2 answers

Does 'session_destroy()' completely destroys and make it unaccessible the super global variable $_SESSION?

I've learnt that session_unset() removes all session variables which means it just clears the $_SESSION variable and it’s equivalent to doing: $_SESSION = array(); This does only affect the local $_SESSION variable instance/s. session_destroy()…
PHPLover
  • 1
  • 51
  • 158
  • 311
1
vote
1 answer

PHP Session Variables are not working on other pages but session_status() is 2

I am Creating a Login System but Unable to access Session Variables on other pages... I have two php files - (1).check_login.php and (2). test.php (1).check_login.php
1
vote
0 answers

What is the proper way to clear super-global variable in PHP?

What is the proper way to clear super-global variable in PHP? Is this way correct? $_GET = array(); Or should I use this way? foreach ($_GET as $k => $v) { unset($_GET[$k]); }
NoSkill
  • 718
  • 5
  • 15