PHP Superglobals

PHP Superglobals

In PHP, superglobals are special predefined variables that are available in all scopes throughout a PHP script. They are called “superglobals” because they can be accessed from any part of the script without the need to explicitly declare or import them.

There are several superglobal variables in PHP, each serving a specific purpose. Here are the most commonly used PHP superglobals:

  1. $_GET: This superglobal variable is an associative array that contains the values of variables passed to the current script via the URL parameters (i.e., the query string). For example, if the URL is http://example.com/script.php?name=John&age=25, you can access the values of name and age using $_GET['name'] and $_GET['age'], respectively.
  2. $_POST: It is also an associative array that holds the values of variables sent to the current script via an HTTP POST request. When you submit an HTML form with the method attribute set to “post,” the form data will be available through this superglobal. You can access the values using the corresponding form field names. For example, $_POST['username'], $_POST['password'], etc.
  3. $_SERVER: This superglobal contains information about the server and the execution environment. It is an associative array that includes details such as request headers, script filenames, server addresses, and more. For example, $_SERVER['REQUEST_METHOD'] will contain the HTTP request method (e.g., GET, POST), and $_SERVER['REMOTE_ADDR'] will provide the IP address of the client.
  4. $_SESSION: It is an associative array that stores session data for the current user. Session data persists across multiple pages or requests within the same session. To use this superglobal, you need to start a session using the session_start() function. Once the session is started, you can store and retrieve data from $_SESSION.
  5. $_COOKIE: This superglobal holds the values of cookies sent by the client browser to the server. Cookies are small pieces of data stored on the client’s machine. In PHP, you can access the cookie values using $_COOKIE['cookiename'].
  6. $_FILES: When you upload files using an HTML form with the enctype attribute set to “multipart/form-data,” the uploaded files’ details will be available in this superglobal. It is an associative array containing information such as the file name, file type, temporary file location, etc.

These are the primary superglobals in PHP that provide a convenient way to access and manipulate data that is commonly used in web applications. Remember to handle superglobal data with caution and sanitize/validate it as necessary to prevent security vulnerabilities like SQL injection or cross-site scripting (XSS) attacks.

Leave a Reply

Your email address will not be published. Required fields are marked *

GLOTRU Footer
Popular Features
Popular Services/

Website Development & Design

App Development & Design

Graphic Design

Digital Marketing

SEO (Search Engine Optimization)

SMM (Social Media Marketing)

Cyber Security

Company

GLOTRU Founder & CEO : __Azam

Registared : Trade,MSME,etc

Board of Director

Team

About Us

Contact Us

Privacy Policy

Return & Refund Policy

Abuse Policy

Copyright Policy

Cookie Policy

Terms & Conditions

Universal Terms of Service

Disclaimer

Legal

Sponsorships

Investor

Press Releases

Our Investments

Brands

Newsroom

Business

...

_

Digital Millennium Copyright Act
DMCA.com Protection Status

_

Content similarity detection
Protected by Copyscape

_

***ANTI-PIRACY WARNING***

...................................................................................

Follow Us :

...................................................................................

SECURE SERVER : [Legal] [Privacy Policy] [Universal Terms of Service] [Do not sell my personal information]

SITE HOSTED : GLOTRU SECURE SERVER Asian Data Centre [You can host your site][Click Here]

SSL : Server Type : [Cloudflare] Certificate Issued By : [Let's Encrypt] Signature Algorithm : [ECDSA with SHA-384]

SITE BUILD SOFTWARE : Content Management System (CMS) Softwere

_

_

_