Fueling Your Coding Mojo

Buckle up, fellow PHP enthusiast! We're loading up the rocket fuel for your coding adventures...

Popular Searches:
20
Q:

superglobals - Where can I get a complete list of variables that PHP automatically makes available to my script by looking at the output of the phpinfo() function?

Hey everyone,

I've been working with PHP recently, and I'm trying to find a comprehensive list of all the variables that are automatically available to my script. I've heard that the output of the `phpinfo()` function can provide this information, but I'm not sure where to look.

I've tried searching online, but most of the resources I've found only explain what `phpinfo()` does or provide basic information about the variables. I'm looking for something more detailed and specific.

Do any of you know where I can find a complete list of these superglobal variables by examining the output of the `phpinfo()` function? I'd really appreciate your help!

Thanks in advance!

All Replies

cooper05

Hey there,

I totally understand your need for a complete list of superglobal variables in PHP. I had a similar requirement a while back and came across a neat trick to find them using the `phpinfo()` function. Here's what you can do:

1. Open a new PHP file and add the following code:

php
<?php
phpinfo();
?>


2. Save the file with a `.php` extension, for example, `superglobals.php`.

3. Upload the file to your server and access it through your browser by visiting `http://your-domain.com/superglobals.php`.

4. The page will show you an extensive output of information about your PHP installation. Scroll down until you find a section called "Variable and Registered PHP Streams."

5. In that section, you'll see a list of superglobals like `$_SERVER`, `$_GET`, `$_POST`, `$_COOKIE`, `$_SESSION`, and several others. Each superglobal will have detailed information about its values and other attributes.

By following these steps, you should be able to locate the complete list of superglobal variables available to your script. It's a great way to explore and understand what each variable does and how it can be utilized in your PHP code.

I hope this helps you out! Let me know if you have any further questions.

kavon.schmitt

Hey!

I see that you're looking for a way to get a comprehensive list of superglobal variables in PHP using the `phpinfo()` function. While the previous response offered a great solution, I'd like to share an alternative approach that I found helpful.

Instead of relying solely on the `phpinfo()` function, you can leverage the built-in `get_defined_vars()` function to obtain a list of all defined variables within your script, including the superglobals. Here's how you can do it:

1. Create a new PHP file, for example, `globals.php`, and add the following code:

php
<?php
foreach ($GLOBALS as $key => $value) {
echo $key . '<br>';
}
?>


2. Save the file and upload it to your server.

3. Access the file through your browser by visiting `http://your-domain.com/globals.php`.

This script will iterate through the `$GLOBALS` array, which contains all the defined variables in your script, including superglobals. By echoing each key, you'll be able to see a list of all variables in your PHP environment, including `$_SERVER`, `$_GET`, `$_POST`, and many more.

This method provides a quick way to identify all superglobal variables, along with any other defined variables in your script.

I hope this alternative solution helps you find the information you're seeking. Let me know if you have any other questions or need further assistance!

New to LearnPHP.org Community?

Join the community