• Home
  • Android
    • Apps
      • Android OS Build App
      • Compare Phone Contracts
        • Example 1
        • Example 2
        • Example 3
        • Example 4
        • Example 5
        • Example 6
      • Lump Sum Savings
  • Articles
  • Free Resources
    • Android Graphics Resources For Use In Apps
  • Index

Tekeye's Technology Blog

Show PHP Settings with phpinfo and Example PHP $_SERVER Display Page

Articles - diana - June 20, 2015

View PHP Environment Configuration Settings and Superglobals on a Page

PHP is a great computer and web site scripting language and extremely popular. It is used primarily for developing interactive web sites and many use it for day-to-day programming tasks. There are several versions in general use and sometimes the configuration of PHP between servers and machines needs to be compared. The phpinfo() function is a one line solution to show the current live PHP set up. To show PHP settings simply create a one line PHP web file on the server containing <?php phpinfo(); ?> and point the browser at it. HTML tags are NOT required because the phpinfo() function pumps them out.

Related Posts:

  • Fiction Writing Tips, SEO, Search Engine Optimization
  • Compare Phone Contracts
  • How to Make a Weebly Website
  • Working on the Run: Tablet or Laptop?
  • How to View Instagram Private Accounts [2021 Guides]
  • Android OS Build App

Note: phpinfo() outputs a lot of useful information, information that hackers find interesting so use it with care. Ideally do not have the phpinfo() page on a public facing web site. On the occasions you do take precautions to reduce information leakage. Put the page in a password protected directory, do not call it phpinfo.php as this is obvious to hackers (use something more obscure and a reminder to delete it when finished, e.g. quick-config-check.php), finally don’t forget to delete it when the PHP settings have been checked.

A PHP script will need access to other settings that PHP provides, often via system wide globals known as the superglobals. The $_SERVER array provides access to the _SERVER superglobal and is shown by phpinfo() in a table. Occasionally it can be worthwhile viewing such values from another PHP file. This can be done in a few lines of code. The following provides some details on showing PHP settings and global values in web pages.

 

Show PHP Settings Examples

Normally a minimal web page would require the following tags for a basic structure:

1
2
3
4
5
6
7
8
9
<!DOCTYPE html>
<html>
<head>
<title>Basic Web Page</title>
</head>
<body>
Content goes here!
</body>
</html>

But to show PHP settings only one line is required. Create a PHP file, e.g. php-test.php, on the web server’s public directory (on an Apache server this default may be /var/www/html). Add the call to phpinfo() to the file and save it:

1
2
3
<?php
    phpinfo();
?>

Point the browser at the web page, e.g. http://www.example.com/php-test.php:

 

This produces a lengthy web page with comprehensive information on the PHP and web server configuration. The PHP variables stored in the $_SERVER global array are towards the end of the page. To see just the variables change the call to phpinfo() to phpinfo(INFO_VARIABLES), for other options for phpinfo() see the phpinfo documentation.

Showing the $_SERVER Settings in a PHP Script

The _SERVER superglobal is an array of useful strings, e.g. REQUEST_URI. Each value or the whole array can be output from any web file to aid debugging, not just through phpinfo(), here is an example a PHP file to print the whole array (to read a single value simple use the key required, e.g. $request_url=$_SERVER[“REQUEST_URI”];):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<head>
<title>$_SERVER</title>
</head>
<body>
        <?php
            print “<table border=1>”;
            foreach ($_SERVER as $key=>$val ){
                print “<tr><td>”.$key.“</td><td>”.$val.“</tr>”;
            }
            print “</table>”;
        ?>
</body>
</html>

Notice the use of the => operator to assign the name of the array key to the $key variable, see the PHP documentation on foreach.

 

See the PHP superglobals documentation for further information.

An alternative method is capture the output of phpinfo() for display in your own PHP files:

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
<title>PHP Settings</title>
</head>
<body>
        <?php
            ob_start();
            phpinfo(INFO_VARIABLES);
            echo ob_get_clean();
        ?>
</body>
</html>

 

Storing and Displaying PHP Application Settings

An array can be used to support configuration information for your PHP application itself. Add the required settings to a key, value array and use the same method as for the superglobals to read the values:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
    $APP_SETTINGS = array(
        “SQLITE_LOCATION” => “data/customers”,
        “SQLITE_NAME” => “customer”,
    );
?>
<!DOCTYPE html>
<html>
<head>
<title>App Settings</title>
</head>
<body>
        <?php
            print “<table border=1><caption>Our Settings ($APP_SETTINGS)</caption>”;
            foreach ($APP_SETTINGS as $key=>$val ){
                print “<tr><td>”.$key.“</td><td>”.$val.“</tr>”;
            }
            print “</table>”;
        ?>
</body>
</html>

 

Displaying PHP Magic Constants

There are eight constants available that relate to the particular PHP script being executed, see the PHP Magic constants documentation for information on all eight. The __DIR__ and __FILE__ constants are probably the most used of the eight:

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html>
<head>
<title>Script</title>
</head>
<body>
        <?php
            echo “<p>”.__DIR__.“</p>”;
            echo “<p>”.__FILE__.“</p>”;
        ?>
</body>
</html>

 

A Comprehensive Web Page to Show PHP Settings

Finally combining the information discussed here it is possible to produce a PHP page that displays a lot of useful environment and application information:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
    $APP_SETTINGS = array(
        “SQLITE_LOCATION” => “data/customers”,
        “SQLITE_NAME” => “customer”,
    );
?>
<!DOCTYPE html>
<html>
<head>
<title>Script</title>
</head>
<body>
        <?php
            echo “<table border=1><caption>Our Settings ($APP_SETTINGS)</caption>”;
            foreach ($APP_SETTINGS as $key=>$val ){
                echo “<tr><td>”.$key.“</td><td>”.$val.“</tr>”;
            }
            echo “</table>”;
            echo “<p>Script directory: “.__DIR__.“</p>”;
            echo “<p>PHP File: “.__FILE__.“</p>”;
            ob_start();
            phpinfo(INFO_VARIABLES);
            echo ob_get_clean();
        ?>
</body>
</html>

 0 0

Share This Post!

About Author / diana

No Comment

Leave a Reply Cancel Reply

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

Previous Post
Next Post

About Me

Thanks for visits my website, hope you like my posts

Recent Posts

  • When Is Fortnite Mobile Coming Back?
  • Google Meet Up Games – An Interactive Way for Children to Learn and Have Fun Online
  • Free Download Grand Theft Auto Mobile
  • Laptop Repair St Louis
  • Law Office Linux: Good change is good. (A discussion regarding Rocket Matter and SaaS.)
  • How to do shopping online articles
  • How to Delete Game Data From a Google Play Account
  • Michigan State vs Notre Dame – What to Expect
  • Middle Aged Woman Blogging: Angelina Jolie’s Lips
  • Online Gaming Solutions For Legal Entertainment
  • Online Marketing Methods
  • Find Out Why Online Affiliate Marketing Works For Me
  • Fiction Writing Tips, SEO, Search Engine Optimization
  • Technology Blogs Made Simple, Try These Tips!
  • How to Earn Money Online Free

Archives

  • January 2022
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • January 2016
  • June 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015

Widget Area 1

Assign a Widget

Widget Area 2

Assign a Widget

Widget Area 3

Assign a Widget

Alison is a creative soft blog theme made with by angrygorilla.

  • vídeo de mulher nua
  • porno casero
  • free porno