3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /* * User connection info * * License: GPL v2 (https://www.gnu.org/licenses/gpl-2.0.html) * * Copyright (C) 2014 Sergey Briskin (http://briskin.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ // Create array of values $user = array( 'ip' => $_SERVER['REMOTE_ADDR'], 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""), 'port' => $_SERVER['REMOTE_PORT'], 'ua' => $_SERVER['HTTP_USER_AGENT'], 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], 'mime' => $_SERVER['HTTP_ACCEPT'], 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'], 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'], 'connection' => $_SERVER['HTTP_CONNECTION'], 'cache' => $_SERVER['HTTP_CACHE_CONTROL'], 'cookie' => $_SERVER['HTTP_COOKIE'], 'referer' => $_SERVER['HTTP_REFERER'], 'real_ip' => $_SERVER['HTTP_X_REAL_IP'], 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'], 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""), 'dnt' => $_SERVER['HTTP_DNT'] ); // Check request (ex. ifconfig.php?q=ip) $query=trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($_GET['q'])))))); // Return single value on request & die if (isset($query) && array_key_exists($query, $user)) { empty($user[$query]) ? die() : die($user[$query]."\n"); } // Return full output in one of supported formats (html, text, xml, json. default: html) elseif (isset($query) && (($query=="text") || ($query=="all"))) { header('Content-Type: text/plain'); foreach($user as $key => $value) { echo $key.": ".$value."\n"; } die(); } elseif (isset($query) && ($query=="xml")) { header('Content-Type: text/xml'); // Function for SimpleXML creation function array_to_xml(array $arr, SimpleXMLElement $xml) { foreach ($arr as $k => $v) { is_array($v) ? array_to_xml($v, $xml->addChild($k)) : $xml->addChild($k, $v); } return $xml; } echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML(); } elseif (isset($query) && ($query=="json")) { header('Content-Type: application/json'); die(json_encode($user)); } else { header('Content-Type: text/html'); ?><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>info</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> <style> body { background: #FDFDFD; color: #111; font-size: .9em; } p { font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed; line-height: 1em; } .small, .small > a { font-size: 9pt; color: #777; text-align: center; text-decoration: none; } </style> </head> <body> <? foreach($user as $key => $value) { echo ' <p id="'.$key.'">'.$key.': '.$value.'</p>'."\n"; } ?> <br/> <p class="small">Copyright &copy; 2014 <a href="http://briskin.org">Sergey Briskin</a>.<br/> <a href="https://github.com/sbriskin/ifconfig.php">Get Source code on GitHub</a></p> </body> </html> <? } die(); ?>
based on ml7kS
Output for 5.4.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined index: REMOTE_ADDR in /in/2PkT3 on line 27 Notice: Undefined index: REMOTE_PORT in /in/2PkT3 on line 29 Notice: Undefined index: HTTP_USER_AGENT in /in/2PkT3 on line 30 Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /in/2PkT3 on line 31 Notice: Undefined index: HTTP_ACCEPT in /in/2PkT3 on line 32 Notice: Undefined index: HTTP_ACCEPT_ENCODING in /in/2PkT3 on line 33 Notice: Undefined index: HTTP_ACCEPT_CHARSET in /in/2PkT3 on line 34 Notice: Undefined index: HTTP_CONNECTION in /in/2PkT3 on line 35 Notice: Undefined index: HTTP_CACHE_CONTROL in /in/2PkT3 on line 36 Notice: Undefined index: HTTP_COOKIE in /in/2PkT3 on line 37 Notice: Undefined index: HTTP_REFERER in /in/2PkT3 on line 38 Notice: Undefined index: HTTP_X_REAL_IP in /in/2PkT3 on line 39 Notice: Undefined index: HTTP_X_FORWARDED_FOR in /in/2PkT3 on line 40 Notice: Undefined index: HTTP_DNT in /in/2PkT3 on line 42 Notice: Undefined index: q in /in/2PkT3 on line 46 Warning: Cannot modify header information - headers already sent by (output started at /in/2PkT3:27) in /in/2PkT3 on line 80 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>info</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> <style> body { background: #FDFDFD; color: #111; font-size: .9em; } p { font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed; line-height: 1em; } .small, .small > a { font-size: 9pt; color: #777; text-align: center; text-decoration: none; } </style> </head> <body> <p id="ip">ip: </p> <p id="host">host: </p> <p id="port">port: </p> <p id="ua">ua: </p> <p id="lang">lang: </p> <p id="mime">mime: </p> <p id="encoding">encoding: </p> <p id="charset">charset: </p> <p id="connection">connection: </p> <p id="cache">cache: </p> <p id="cookie">cookie: </p> <p id="referer">referer: </p> <p id="real_ip">real_ip: </p> <p id="fwd_ip">fwd_ip: </p> <p id="fwd_host">fwd_host: </p> <p id="dnt">dnt: </p> <br/> <p class="small">Copyright &copy; 2014 <a href="http://briskin.org">Sergey Briskin</a>.<br/> <a href="https://github.com/sbriskin/ifconfig.php">Get Source code on GitHub</a></p> </body> </html>
Output for hhvm-3.12.0 - 3.13.2
Notice: Undefined index: REMOTE_ADDR in /in/2PkT3 on line 27 Notice: Undefined index: REMOTE_PORT in /in/2PkT3 on line 29 Notice: Undefined index: HTTP_USER_AGENT in /in/2PkT3 on line 30 Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /in/2PkT3 on line 31 Notice: Undefined index: HTTP_ACCEPT in /in/2PkT3 on line 32 Notice: Undefined index: HTTP_ACCEPT_ENCODING in /in/2PkT3 on line 33 Notice: Undefined index: HTTP_ACCEPT_CHARSET in /in/2PkT3 on line 34 Notice: Undefined index: HTTP_CONNECTION in /in/2PkT3 on line 35 Notice: Undefined index: HTTP_CACHE_CONTROL in /in/2PkT3 on line 36 Notice: Undefined index: HTTP_COOKIE in /in/2PkT3 on line 37 Notice: Undefined index: HTTP_REFERER in /in/2PkT3 on line 38 Notice: Undefined index: HTTP_X_REAL_IP in /in/2PkT3 on line 39 Notice: Undefined index: HTTP_X_FORWARDED_FOR in /in/2PkT3 on line 40 Notice: Undefined index: HTTP_DNT in /in/2PkT3 on line 42 Notice: Undefined index: q in /in/2PkT3 on line 46 Warning: strip_tags() expects parameter 1 to be string, null given in /in/2PkT3 on line 46 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>info</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> <style> body { background: #FDFDFD; color: #111; font-size: .9em; } p { font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed; line-height: 1em; } .small, .small > a { font-size: 9pt; color: #777; text-align: center; text-decoration: none; } </style> </head> <body> <p id="ip">ip: </p> <p id="host">host: </p> <p id="port">port: </p> <p id="ua">ua: </p> <p id="lang">lang: </p> <p id="mime">mime: </p> <p id="encoding">encoding: </p> <p id="charset">charset: </p> <p id="connection">connection: </p> <p id="cache">cache: </p> <p id="cookie">cookie: </p> <p id="referer">referer: </p> <p id="real_ip">real_ip: </p> <p id="fwd_ip">fwd_ip: </p> <p id="fwd_host">fwd_host: </p> <p id="dnt">dnt: </p> <br/> <p class="small">Copyright &copy; 2014 <a href="http://briskin.org">Sergey Briskin</a>.<br/> <a href="https://github.com/sbriskin/ifconfig.php">Get Source code on GitHub</a></p> </body> </html>
Output for hhvm-3.10.0
Notice: Undefined index: REMOTE_ADDR in /in/2PkT3 on line 27 Notice: Undefined index: REMOTE_PORT in /in/2PkT3 on line 29 Notice: Undefined index: HTTP_USER_AGENT in /in/2PkT3 on line 30 Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /in/2PkT3 on line 31 Notice: Undefined index: HTTP_ACCEPT in /in/2PkT3 on line 32 Notice: Undefined index: HTTP_ACCEPT_ENCODING in /in/2PkT3 on line 33 Notice: Undefined index: HTTP_ACCEPT_CHARSET in /in/2PkT3 on line 34 Notice: Undefined index: HTTP_CONNECTION in /in/2PkT3 on line 35 Notice: Undefined index: HTTP_CACHE_CONTROL in /in/2PkT3 on line 36 Notice: Undefined index: HTTP_COOKIE in /in/2PkT3 on line 37 Notice: Undefined index: HTTP_REFERER in /in/2PkT3 on line 38 Notice: Undefined index: HTTP_X_REAL_IP in /in/2PkT3 on line 39 Notice: Undefined index: HTTP_X_FORWARDED_FOR in /in/2PkT3 on line 40 Notice: Undefined index: HTTP_DNT in /in/2PkT3 on line 42 Notice: Undefined index: q in /in/2PkT3 on line 46 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>info</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> <style> body { background: #FDFDFD; color: #111; font-size: .9em; } p { font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed; line-height: 1em; } .small, .small > a { font-size: 9pt; color: #777; text-align: center; text-decoration: none; } </style> </head> <body> <p id="ip">ip: </p> <p id="host">host: </p> <p id="port">port: </p> <p id="ua">ua: </p> <p id="lang">lang: </p> <p id="mime">mime: </p> <p id="encoding">encoding: </p> <p id="charset">charset: </p> <p id="connection">connection: </p> <p id="cache">cache: </p> <p id="cookie">cookie: </p> <p id="referer">referer: </p> <p id="real_ip">real_ip: </p> <p id="fwd_ip">fwd_ip: </p> <p id="fwd_host">fwd_host: </p> <p id="dnt">dnt: </p> <br/> <p class="small">Copyright &copy; 2014 <a href="http://briskin.org">Sergey Briskin</a>.<br/> <a href="https://github.com/sbriskin/ifconfig.php">Get Source code on GitHub</a></p> </body> </html>
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected $end in /in/2PkT3 on line 119
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/2PkT3 on line 64
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/2PkT3 on line 64
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/2PkT3 on line 64
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/2PkT3 on line 64
Process exited with code 255.