3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // This is the automatic DB push code // This value is pulled from the HTTP server $spaces=" "; $yikes ="!!!!!!!!"; $IPAddress = $_SERVER['REMOTE_ADDR']; $dieClose = " </body> </html>\n"; if ( empty ( $_POST ) ) { die ( "No variables passed in on HTTP POST" . $dieClose );//GET variables have been set } //setup filters to prevent invalid data input and malicious code insertion $filters = array ( "eventid" => array ("filter"=>FILTER_VALIDATE_REGEXP, // STRING epoch date int followed by "_" followed by an IP address i.e.: "1384204604_172.16.198.48" "options"=>array("regexp"=>"/^([0-9]+)_(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/")), "oslist" => array ("filter"=>FILTER_VALIDATE_REGEXP, // STRING (alnum and "," only), CSV OS name list. i.e.: "win7x64,debianx64,dos" "options"=>array("regexp"=>"/^((([a-zA-Z0-9]+),)*)([a-zA-Z0-9_]+)$/")), "hostip" => array ("filter"=>FILTER_VALIDATE_IP), "state" => array ("filter"=>FILTER_VALIDATE_REGEXP, // STRING characters "s" and "e" ONLY!!! indicates "start" or "end" "options"=>array("regexp"=>"/^[se]$/")), "hddinfo" => array ("filter"=>FILTER_VALIDATE_REGEXP, // STRING (0-9 and "," only), CSV HDD size list in kB i.e. "12313,123123,1132" "options"=>array("regexp"=>"/^((\d+,)*)(\d+)$/")), "meminfo" => array ("filter"=>FILTER_SANITIZE_STRING), "cpuinfo" => array ("filter"=>FILTER_SANITIZE_STRING), "error" => array ("filter"=>FILTER_VALIDATE_INT, "options"=>array("min_range"=>0,"max_range"=>1024) ), ); $inputFields = filter_input_array(INPUT_POST, $filters); //var_dump($inputFields); //for debugging $DBfields=array("eventid", "oslist", "hostip", "state", "hddinfo", "meminfo", "cpuinfo", "error"); $Results =array(); //$keyvalue="eventid"; foreach ($DBfields as &$keyvalue) { if (!$inputFields[$keyvalue]) { die($yikes . $keyvalue . "=" . $_POST[$keyvalue] . " invalid" . $yikes . $dieClose); } else { //echo($spaces . "Got a valid " . $keyvalue . "=" . $inputFields[$keyvalue] . "\n" ); //for debugging $Results[$keyvalue] = $inputFields[$keyvalue]; } } $MyQuery = "INSERT INTO `clonestats`.`stattable` ( `eventid`, `oslist`, `hostip`, `state`, `hddinfo`, `meminfo`, `cpuinfo`, `error` ) " . "VALUES ( '" . $Results['eventid'] . "', '" . $Results['oslist'] . "', '" . $IPAddress . ", " . $Results['hostip'] . "','" . $Results['state'] . "', '" . $Results['hddinfo'] . "', '" . $Results['meminfo'] . "', '" . $Results['cpuinfo'] . "', '" . $Results['error'] . "' );"; //echo("my query is \n\t$MyQuery"); //for debugging only $NewDBConnection = mysql_connect ( "localhost", "CloneStatPush", "5a97114c932162a11622eb34cb2589586ffa70fb7ee85d267c8dc06ba3de2a9c" ); if (!$NewDBConnection) { die ( "\n".$yikes." I didn't successfully connect to the database" . $yikes . $dieClose ); // link to DB is bad } else { mysql_select_db ( "clonestats" ); // echo $MyQuery; mysql_query ( $MyQuery ); echo mysql_affected_rows ( ); // Prints the result of the INSERT command, client doesn't need to do anything with it mysql_close ( $DBlink ); } ?>
Output for 5.3.6 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Notice: Undefined index: REMOTE_ADDR in /in/Fmcj8 on line 6 No variables passed in on HTTP POST </body> </html>
Output for hhvm-3.10.0

Process exited with code 153.