get_defined_vars

Returns an array of all defined variables

Syntax

get_defined_vars(): array

Return

A multidimensional array with all the variables.

Examples

1

<?

$return = get_defined_vars();

print_r($return);

?>
Array
(
    [_GET] => Array
        (
        )

    [_POST] => Array
        (
        )

    [_COOKIE] => Array
        (
        )

    [_FILES] => Array
        (
        )

    [_SERVER] => Array
        (
            [PATH] => /usr/local/bin:/bin:/usr/bin
            [HTTP_ACCEPT] => */*
            [HTTP_HOST] => osbo.com
            [HTTP_X_HTTPS] => 1
            [DOCUMENT_ROOT] => /home/osbocom/public_html
            [REMOTE_ADDR] => 212.1.210.51
            [REMOTE_PORT] => 28066
            [SERVER_ADDR] => 212.1.210.80
            [SERVER_NAME] => osbo.com
            [SERVER_ADMIN] => webmaster@osbo.com
            [SERVER_PORT] => 443
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /php/demo/
            [GEOIP_ADDR] => 212.1.210.51
            [GEOIP_CONTINENT_CODE] => EU
            [GEOIP_COUNTRY_CODE] => CY
            [GEOIP_COUNTRY_NAME] => Cyprus
            [GEOIP_CITY_CONTINENT_CODE] => EU
            [GEOIP_CITY_COUNTRY_CODE] => CY
            [GEOIP_CITY_COUNTRY_NAME] => Cyprus
            [GEOIP_LATITUDE] => 35.00000
            [GEOIP_LONGITUDE] => 33.00000
            [GEOIP_ISP] => 47583
            [GEOIP_ORGANIZATION] => Hostinger International Limited
            [HTTPS] => on
            [CRAWLER_USLEEP] => 1000
            [CRAWLER_LOAD_LIMIT_ENFORCE] => 20
            [X_SPDY] => HTTP2
            [SSL_PROTOCOL] => TLSv1.3
            [SSL_CIPHER] => TLS_AES_256_GCM_SHA384
            [SSL_CIPHER_USEKEYSIZE] => 256
            [SSL_CIPHER_ALGKEYSIZE] => 256
            [SCRIPT_FILENAME] => /home/osbocom/public_html/php/demo/index.php
            [QUERY_STRING] => 
            [SCRIPT_URI] => https://osbo.com/php/demo/
            [SCRIPT_URL] => /php/demo/
            [SCRIPT_NAME] => /php/demo/index.php
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SOFTWARE] => LiteSpeed
            [REQUEST_METHOD] => GET
            [X-LSCACHE] => on,crawler
            [PHP_SELF] => /php/demo/index.php
            [REQUEST_TIME_FLOAT] => 1660450528.7638
            [REQUEST_TIME] => 1660450528
        )

)

2

<?

$array = array(true, 12.34, "abc", array(0, 1));

$return = get_defined_vars();

print_r($return);

?>
Array
(
    [_GET] => Array
        (
        )

    [_POST] => Array
        (
        )

    [_COOKIE] => Array
        (
        )

    [_FILES] => Array
        (
        )

    [_SERVER] => Array
        (
            [PATH] => /usr/local/bin:/bin:/usr/bin
            [HTTP_ACCEPT] => */*
            [HTTP_HOST] => osbo.com
            [HTTP_X_HTTPS] => 1
            [DOCUMENT_ROOT] => /home/osbocom/public_html
            [REMOTE_ADDR] => 212.1.210.51
            [REMOTE_PORT] => 28068
            [SERVER_ADDR] => 212.1.210.80
            [SERVER_NAME] => osbo.com
            [SERVER_ADMIN] => webmaster@osbo.com
            [SERVER_PORT] => 443
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /php/demo/
            [GEOIP_ADDR] => 212.1.210.51
            [GEOIP_CONTINENT_CODE] => EU
            [GEOIP_COUNTRY_CODE] => CY
            [GEOIP_COUNTRY_NAME] => Cyprus
            [GEOIP_CITY_CONTINENT_CODE] => EU
            [GEOIP_CITY_COUNTRY_CODE] => CY
            [GEOIP_CITY_COUNTRY_NAME] => Cyprus
            [GEOIP_LATITUDE] => 35.00000
            [GEOIP_LONGITUDE] => 33.00000
            [GEOIP_ISP] => 47583
            [GEOIP_ORGANIZATION] => Hostinger International Limited
            [HTTPS] => on
            [CRAWLER_USLEEP] => 1000
            [CRAWLER_LOAD_LIMIT_ENFORCE] => 20
            [X_SPDY] => HTTP2
            [SSL_PROTOCOL] => TLSv1.3
            [SSL_CIPHER] => TLS_AES_256_GCM_SHA384
            [SSL_CIPHER_USEKEYSIZE] => 256
            [SSL_CIPHER_ALGKEYSIZE] => 256
            [SCRIPT_FILENAME] => /home/osbocom/public_html/php/demo/index.php
            [QUERY_STRING] => 
            [SCRIPT_URI] => https://osbo.com/php/demo/
            [SCRIPT_URL] => /php/demo/
            [SCRIPT_NAME] => /php/demo/index.php
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SOFTWARE] => LiteSpeed
            [REQUEST_METHOD] => GET
            [X-LSCACHE] => on,crawler
            [PHP_SELF] => /php/demo/index.php
            [REQUEST_TIME_FLOAT] => 1660450528.7772
            [REQUEST_TIME] => 1660450528
        )

    [array] => Array
        (
            [0] => 1
            [1] => 12.34
            [2] => abc
            [3] => Array
                (
                    [0] => 0
                    [1] => 1
                )

        )

)

3

<?

$array = array(true, 12.34, "abc", array(0, 1));

$return = get_defined_vars();

print_r($return["array"]);

?>
Array
(
    [0] => 1
    [1] => 12.34
    [2] => abc
    [3] => Array
        (
            [0] => 0
            [1] => 1
        )

)

4

<?

$return = get_defined_vars();

print_r($return["_SERVER"]);

?>
Array
(
    [PATH] => /usr/local/bin:/bin:/usr/bin
    [HTTP_ACCEPT] => */*
    [HTTP_HOST] => osbo.com
    [HTTP_X_HTTPS] => 1
    [DOCUMENT_ROOT] => /home/osbocom/public_html
    [REMOTE_ADDR] => 212.1.210.51
    [REMOTE_PORT] => 28072
    [SERVER_ADDR] => 212.1.210.80
    [SERVER_NAME] => osbo.com
    [SERVER_ADMIN] => webmaster@osbo.com
    [SERVER_PORT] => 443
    [REQUEST_SCHEME] => https
    [REQUEST_URI] => /php/demo/
    [GEOIP_ADDR] => 212.1.210.51
    [GEOIP_CONTINENT_CODE] => EU
    [GEOIP_COUNTRY_CODE] => CY
    [GEOIP_COUNTRY_NAME] => Cyprus
    [GEOIP_CITY_CONTINENT_CODE] => EU
    [GEOIP_CITY_COUNTRY_CODE] => CY
    [GEOIP_CITY_COUNTRY_NAME] => Cyprus
    [GEOIP_LATITUDE] => 35.00000
    [GEOIP_LONGITUDE] => 33.00000
    [GEOIP_ISP] => 47583
    [GEOIP_ORGANIZATION] => Hostinger International Limited
    [HTTPS] => on
    [CRAWLER_USLEEP] => 1000
    [CRAWLER_LOAD_LIMIT_ENFORCE] => 20
    [X_SPDY] => HTTP2
    [SSL_PROTOCOL] => TLSv1.3
    [SSL_CIPHER] => TLS_AES_256_GCM_SHA384
    [SSL_CIPHER_USEKEYSIZE] => 256
    [SSL_CIPHER_ALGKEYSIZE] => 256
    [SCRIPT_FILENAME] => /home/osbocom/public_html/php/demo/index.php
    [QUERY_STRING] => 
    [SCRIPT_URI] => https://osbo.com/php/demo/
    [SCRIPT_URL] => /php/demo/
    [SCRIPT_NAME] => /php/demo/index.php
    [SERVER_PROTOCOL] => HTTP/1.1
    [SERVER_SOFTWARE] => LiteSpeed
    [REQUEST_METHOD] => GET
    [X-LSCACHE] => on,crawler
    [PHP_SELF] => /php/demo/index.php
    [REQUEST_TIME_FLOAT] => 1660450528.8116
    [REQUEST_TIME] => 1660450528
)

PHP

Home Menu