Beginner PHP Tutorial - 6 - The phpinfo Function

visibility 20 wyświetleń schedule 10 lat temu timer 5:00
open_in_new Dailymotion
To view phpinfo() output on our servers, you must have an A2 Hosting account. The information revealed by the phpinfo() function poses a potential security risk, so we do not post it publicly. Hackers and other malicious actors could use the information from phpinfo() to plan an attack. <br />bool phpinfo ([ int $what = INFO_ALL ] ) <br />Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License. <br /> <br />Because every system is setup differently, phpinfo() is commonly used to check configuration settings and for available predefined variables on a given system. <br /> <br />phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data. <br /> <br />Parameters <br /> <br />what <br />The output may be customized by passing one or more of the following constants bitwise values summed together in the optional what parameter. One can also combine the respective constants or bitwise values together with the or operator. <br />One note on the very useful example by "jon at sitewizard dot ca". <br />The following statements: <br />Statement 1: <br />$phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3]; <br />Statement 2: <br />$phpinfo[end(array_keys($phpinfo))][] = $match[2]; <br /> <br />These two lines will produce the error "Strict Standards: Only variables should be passed by reference in...". The root of the error is in the incorrect use of the end() function. The code works but thows the said error. <br />To address this try using the following statements: <br /> <br />Statement 1 revision: <br />$keys = array_keys($phpinfo); <br />$phpinfo[end($keys)][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3]; <br /> <br />Statement 2 revision: <br />$keys = array_keys($phpinfo); <br />$phpinfo[end($keys)][] = $match[2]; <br /> <br />This fixes the error. <br />To wrap it all in an example: <br /> array()); <br /> <br /> if(preg_match_all('#(?:(?:)?(.*?)(?:</a>)?)|(?:(.*?)\s*(?:(.*?)\s*(?:(.*?)\s*)?)?)#s', ob_get_clean(), $matches, PREG_SET_ORDER)){ <br /> foreach($matches as $match){ <br /> if(strlen($match[1])){ <br /> $phpinfo[$match[1]] = array(); <br /> }elseif(isset($match[3])){ <br /> $keys1 = array_keys($phpinfo); <br /> $phpinfo[end($keys1)][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3]; <br /> }else{ <br /> $keys1 = array_keys($phpinfo); <br /> $phpinfo[end($keys1)][] = $match[2]; <br /> <br /> } <br /> <br /> } <br />} <br /> <br /> if(! empty($phpinfo)){ <br /> foreach($phpinfo as $name => $section) { <br /> echo "$name\n\n"; <br /> foreach($section as $key => $val){ <br /> if(is_array($val)){ <br /> echo "$key$val[0]$val[1]\n"; <br /> }elseif(is_string($key)){ <br /> echo "$key$val\n"; <br /> }else{ <br /> echo "$val\n"; <br /> } <br /> } <br /> } <br /> echo "\n"; <br /> }else{ <br /> echo "Sorry, the phpinfo() function is not accessable. Perhaps, it is disabledSee the documentation.</a>"; <br /> } <br />} <br />?> <br />Frankly, I went thought the trouble of adding this note because the example by "jon at sitewizard dot ca" is probably the best on the web, and thought it unfortunate that it throws errors. Hope this is useful to someone.