• 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.

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>

Related posts:

  1. Upgrade PHP for CentOS 6 Using Additional Repositories
  2. PHP on Windows Using WebMatrix Single Click Install
  3. Responsive Menu Tutorial for HTML Web Pages, No JQuery
  4. Develop a Website on Windows Using Microsoft WebMatrix
 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

  • How To Control Your Mac With Your iPhone From Anywhere
  • How To Solve Windows System Crashes
  • Working on the Run: Tablet or Laptop?
  • Simple Copywriting System
  • Best Mod Apk Games Market
  • Data Recovery and the Three Golden Backups
  • Responsive Menu Tutorial for HTML Web Pages, No JQuery
  • Show PHP Settings with phpinfo and Example PHP $_SERVER Display Page
  • Upgrade PHP for CentOS 6 Using Additional Repositories
  • Unzip File on VPS? How to Extract a Zip File on a Linux VPS
  • Encrypt Decrypt of a String in C# .NET
  • WebMatrix Rename Site and Changing Virtual Folder Name
  • PHP on Windows Using WebMatrix Single Click Install
  • Develop a Website on Windows Using Microsoft WebMatrix
  • CentOS 6 to CentOS 7 Upgrade Using Red Hat Upgrade Tool

Archives

  • 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.