Last active
December 17, 2015 04:38
-
-
Save RupGautam/d4c28087e1dc73346710 to your computer and use it in GitHub Desktop.
Custom phpinfo page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // set the default timezone to use | |
| date_default_timezone_set('America/Winnipeg'); | |
| // Utility functions | |
| function prettyPrint(array $value) | |
| { | |
| echo "<pre>"; | |
| print_r($value); | |
| echo "</pre>"; | |
| } | |
| function getEnvironment() | |
| { | |
| if (isset($_SERVER['SERVER_ENV']) and !is_null($_SERVER['SERVER_ENV'])) { | |
| return $_SERVER['SERVER_ENV']; | |
| } else { | |
| $environments = ['development', 'test', 'production']; | |
| $doc_pieces = explode("/", strtolower($_SERVER['DOCUMENT_ROOT'])); | |
| foreach ($environments as $environment) { | |
| if (in_array($environment, $doc_pieces)) { | |
| if (in_array('library', $doc_pieces)) { | |
| return "local-$environment"; | |
| } | |
| return $environment; | |
| } | |
| } | |
| } | |
| return null; | |
| } | |
| function getDomain() | |
| { | |
| $url_piece = explode('.', $_SERVER['SERVER_NAME']); | |
| if (count($url_piece) > 2) { | |
| return $url_piece[1] . '.' . $url_piece[2]; | |
| } elseif (count($url_piece) == 2) { | |
| return $url_piece[0] . '.' . $url_piece[1]; | |
| } else { | |
| return $_SERVER['SERVER_NAME']; // example 'localhost' | |
| } | |
| } | |
| function getApp() | |
| { | |
| $url_piece = explode('.', $_SERVER['SERVER_NAME']); | |
| if (count($url_piece) > 2 ) { | |
| $string = $url_piece[0]; | |
| $apps = [ | |
| 'web' => ['www', 'dev', 'test', 'd', 't'], | |
| 'custom' => ['cst', 'dev-cst', 'test-cst', 'c', 'd-c', 't-c'], | |
| 'mobile' => ['mbl', 'dev-mbl', 'test-mbl', 'm', 'd-m', 't-m'], | |
| ]; | |
| foreach ($apps as $key => $values) { | |
| if (in_array($string, $values)) { | |
| /** @var $key string */ | |
| return $key; | |
| } | |
| } | |
| } else { // It can only be a web application | |
| return "web"; | |
| } | |
| return null; | |
| } | |
| function getSubDomain() | |
| { | |
| $env = getEnvironment(); | |
| $app = getApp(); | |
| $domain = getDomain(); | |
| // Set the logic for environments | |
| if (strpos($env, 'development') !== true) { | |
| $short_env_key = 'd'; | |
| $long_env_key = 'dev'; | |
| } elseif (strpos($env, 'test') !== true) { | |
| $short_env_key = 't'; | |
| $long_env_key = 'test'; | |
| } elseif (strpos($env, 'production') !== true) { | |
| $short_env_key = ''; | |
| $long_env_key = ''; | |
| } else { | |
| return "Environment not supported: '$env'"; | |
| } | |
| // Set the logic for applications | |
| if ($app == 'custom') { | |
| $short_app_key = 'c'; | |
| $long_app_key = 'cst'; | |
| } elseif ($app == 'mobile') { | |
| $short_app_key = 'm'; | |
| $long_app_key = 'mbl'; | |
| } elseif ($app == 'web') { | |
| $short_app_key = ''; | |
| $long_app_key = 'www'; | |
| } else { | |
| return "Application not supported: '$app'"; | |
| } | |
| // Based on all the logic, create appropriate short and/or long subs | |
| if ($env != 'production') { | |
| if ($app != 'web') { | |
| $short_sub = "$short_env_key-$short_app_key"; | |
| $long_sub = "$long_env_key-$long_app_key"; | |
| } else { | |
| $short_sub = $short_env_key; | |
| $long_sub = $long_env_key; | |
| } | |
| } else { | |
| if ($app != 'web') { | |
| $short_sub = $short_app_key; | |
| $long_sub = $long_app_key; | |
| } else { | |
| $long_sub = $long_app_key; | |
| } | |
| } | |
| if ($domain != 'localhost') { | |
| // Add all the subs into our subs array | |
| if (isset($short_sub)) { | |
| $sub_domains['sub'][] = $short_sub; | |
| $sub_domains['url'][] = "$short_sub.$domain"; | |
| } | |
| if (isset($long_sub)) { | |
| $sub_domains['sub'][] = $long_sub; | |
| $sub_domains['url'][] = "$long_sub.$domain"; | |
| } | |
| // Return the found sub domains | |
| if (isset($sub_domains)) { | |
| return implode(", ", $sub_domains['url']); | |
| } | |
| } | |
| return null; | |
| } | |
| function getWebRoot() | |
| { | |
| $www = '/www'; // this is 4 characters | |
| $total_length = strrpos($_SERVER['DOCUMENT_ROOT'], $www) + strlen($www); // Get the full length | |
| if ($total_length > 4) { | |
| return substr_replace($_SERVER['DOCUMENT_ROOT'], '', $total_length); // The full path | |
| } | |
| return null; | |
| } | |
| function getWebServer() | |
| { | |
| $item = explode(' ', $_SERVER['SERVER_SOFTWARE']); | |
| $server_software = str_replace("/", ' ', $item[0]); | |
| if (!empty($server_software) or !is_null($server_software)) { | |
| return $server_software; | |
| } | |
| return null; | |
| } | |
| ?> | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title></title> | |
| <link rel="stylesheet" href=""> | |
| <style> | |
| body, h1, h2, h3, p, ul, ol, li, table, tr, td { | |
| padding: 0; | |
| margin: 0; | |
| font: large/2 Helvetica; | |
| } | |
| li { | |
| list-style: none; | |
| } | |
| li:first-child { | |
| } | |
| h1 { | |
| font-size: xx-large; | |
| color: #B2B2B2; | |
| } | |
| #container { | |
| _width: 845px; | |
| margin-top: 20px; | |
| margin-left: 20px; | |
| } | |
| header { | |
| } | |
| #content { | |
| border: 2px solid #FF3300; | |
| padding: 10px 20px; | |
| display: inline-block; | |
| color: #808080; | |
| } | |
| footer { | |
| color: #B2B2B2; | |
| font-size: smaller; | |
| line-height: 1; | |
| position: fixed; | |
| bottom: 25px; | |
| right: 30px; | |
| text-align: right; | |
| } | |
| .color_red_orange { | |
| color: #FF3300; | |
| } | |
| .color_dark_grey { | |
| color: #666666; | |
| } | |
| .spacing { | |
| letter-spacing: 1px; | |
| } | |
| .orange_shadow { | |
| text-shadow:1px 1px 1px #991F00; | |
| } | |
| .align_right { | |
| text-align:right; | |
| } | |
| .pad { | |
| padding-left: 7px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="container"> | |
| <?php if(isset($_GET['page']) and $_GET['page'] == 'phpinfo'): ?> | |
| <div> | |
| <?php echo phpinfo(); ?> | |
| </div> | |
| <?php else: ?> | |
| <header> | |
| <h1> | |
| @[ <span class="color_red_orange orange_shadow"><?php echo $_SERVER['SERVER_NAME']; ?></span> ] | |
| </h1> | |
| </header> | |
| <div id="content"> | |
| <table> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Machine name:</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo php_uname('n'); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Server IP:</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo $_SERVER["SERVER_ADDR"]; ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Visitor IP:</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo $_SERVER["REMOTE_ADDR"]; ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Domain :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo getDomain(); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Sub domain(s):</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo getSubDomain(); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Environment :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo getEnvironment(); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Application :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo getApp(); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Web server :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo getWebServer(); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Web directory :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo getWebRoot(); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">PHP version :</span></td> | |
| <td class="pad"> | |
| <span class="color_red_orange spacing"> | |
| <?php | |
| //preg_match('/[\d.]*/', phpversion(), $match); | |
| echo phpversion(); | |
| ?> | |
| </span> | |
| </td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">PHP config :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo php_ini_loaded_file(); ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Document root :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo $_SERVER['DOCUMENT_ROOT']; ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">Admin email :</span></td> | |
| <td class="pad"><span class="color_red_orange spacing"><?php echo $_SERVER['SERVER_ADMIN']; ?></span></td> | |
| </tr> | |
| <tr> | |
| <td class="align_right"><span class="color_dark_grey">PHP info :</span></td> | |
| <td class="pad"><a href="?page=phpinfo">Get info</a></td> | |
| </tr> | |
| </table> | |
| </div> | |
| <footer> | |
| <h1> | |
| <span class="color_red_orange orange_shadow"><?php echo getDomain(); ?></span> | |
| </h1> | |
| </footer> | |
| <?php endif; ?> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment