3v4l.org

run code in 300+ PHP versions simultaneously
<?php # You must set this correctly to a # location where you are allowed to # create a file! $guestbook = 'guestbook.dat'; # Choose your own password $adminPassword = '$uP3rDUP3r'; # Hide harmless warning messages that confuse users. # If you have problems and you don't know why, # comment this line out for a while to get more # information from PHP error_reporting (E_ALL ^ (E_NOTICE | E_WARNING)); # No changes required below here $admin = 0; if ($adminPassword == 'Change$') { die("You need to change \$adminPassword first."); } # Undo magic quotes - useless for flat files, # and inadequate and therefore dangerous for databases. See: # http://www.boutell.com/newfaq/creating/magicquotes.html function stripslashes_nested($v) { if (is_array($v)) { return array_map('stripslashes_nested', $v); } else { return stripslashes($v); } } if (get_magic_quotes_gpc()) { $_GET = stripslashes_nested($_GET); $_POST = stripslashes_nested($_POST); } ?> <html> <head> <title>Guestbook</title> </head> <body> <h1 align="center">Triumphant Personal Care Guestbook</h1> <div align="center"> <?php $password = ""; if ($_POST['password'] == $adminPassword) { $admin = 1; $password = $adminPassword; } else if (strlen($_POST['password'])) { echo("<h2>Login Failed (Bad Password)</h2>\n"); } ?> <table border="0" cellpadding="3" cellspacing="3"> <tr><th>Date</th><th>Last Name</th><th>Comment</th> <?php if ($admin) { echo "<th>Controls</th>"; } ?> </tr> <?php if ($_POST['submit']) { $file = fopen($guestbook, "a"); if (!$file) { die("Can't write to guestbook file"); } $date = date('F j, Y, g:i a'); $id = rand(); $name = $_POST['name']; $lastname = $_POST['lastname']; $email = $_POST['email']; $comment = $_POST['comment']; $name = clean($name, 40); $lastname = clean($lastname, 40); $email = clean($email, 40); $comment = clean($comment, 40); fwrite($file, "$date\t$name\t$lastname\t$email\t$comment\t$id\n"); fclose($file); } $file = fopen($guestbook, 'r'); $tfile = null; $delete = 0; $deleteId = ''; if ($admin && $_POST['delete']) { $delete = 1; $deleteId = $_POST['id']; $tfile = @fopen("$guestbook.tmp", 'w'); if (!$tfile) { die("Can't create temporary file for delete operation"); } } if ($file) { while (!feof($file)) { $line = fgets($file); $line = trim($line); list ($date, $name, $lastname, $email, $comment, $id) = split("\t", $line, 6); if (!strlen($date)) { break; } if (!strlen($id)) { // Support my old version $id = $date; } if ($delete) { if ($id == $deleteId) { continue; } else { fwrite($tfile, "$date\t$name\t$lastname\t$email\t$comment\t$id\n"); } } echo "<tr><td>$date</td><td>$lastname</td><td>$comment</td>"; if ($admin) { echo "<td>"; echo "<form action=\"keith.php\" " . "method=\"POST\">"; passwordField(); hiddenField('id', $id); echo "<input type=\"submit\" " . "value=\"Delete\" " . "name=\"delete\">"; echo "</form>"; echo "</td>"; } echo "</tr>\n"; } fclose($file); if ($delete) { fclose($tfile); unlink($guestbook); rename("$guestbook.tmp", $guestbook); } } function clean($name, $max) { # Turn tabs and CRs into spaces so they can't # fake other fields or extra entries $name = ereg_replace("[[:space:]]", ' ', $name); # Escape < > and and & so they # can't mess withour HTML markup $name = ereg_replace('&', '&amp;', $name); $name = ereg_replace('<', '&lt;', $name); $name = ereg_replace('>', '&gt;', $name); # Don't allow excessively long entries $name = substr($name, 0, $max); # Undo PHP's "magic quotes" feature, which has # inserted a \ in front of any " characters. # We undo this because we're using a file, not a # database, so we don't want " escaped. Those # using databases should do the opposite: # call addslashes if get_magic_quotes_gpc() # returns false. return $name; } function passwordField() { global $admin; global $password; if (!$admin) { return; } hiddenField('password', $password); } function hiddenField($name, $value) { echo "<input type=\"hidden\" " . "name=\"$name\" value=\"$value\">"; } ?> </table> <?php if (!$admin) { ?> <form action="keith.php" method="POST"> <b>Admin Login</b> <p> Admin Password: <input type="password" name="password"> <input type="submit" name="login" value="Log In"> </form> <?php } ?> <form action="keith.php" method="POST"> <table border="0" cellpadding="5" cellspacing="5"> <tr> <td colspan="2">Sign My Guestbook!</td> </tr> <tr> <th>Name</th><td><input name="name" maxlength="40"></td> </tr> <tr> <th>Last Name</th><td><input name="lastname" maxlength="40"></td> </tr> <tr> <th>Email</th><td><input name="email" maxlength="40"></td> </tr> <tr> <th>Comment</th><td><input name="comment" maxlength="40"></td> </tr> <tr> <th colspan="2"> <input type="submit" name="submit" value="Sign the Guestbook"> </th> </tr> </table> <?php passwordField(); ?> </form> </div> </body> </html>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.1.70.0000.00816.93
7.1.60.0100.01319.17
7.1.50.0090.01217.14
7.1.00.0070.03022.33
7.0.200.0030.00616.82
7.0.140.0000.08022.09
7.0.100.0330.07020.09
7.0.90.0200.08020.06
7.0.80.0100.08320.02
7.0.70.0170.08019.94
7.0.60.0100.07020.16
7.0.50.0200.08320.41
7.0.40.0070.04720.13
7.0.30.0170.05320.04
7.0.20.0030.08320.15
7.0.10.0030.09320.04
7.0.00.0030.09020.09
5.6.280.0030.07321.19
5.6.250.0070.08720.75
5.6.240.0030.06720.61
5.6.230.0070.05020.69
5.6.220.0100.07720.65
5.6.210.0100.08020.73
5.6.200.0130.07321.07
5.6.190.0070.08321.07
5.6.180.0100.07721.08
5.6.170.0030.04721.05
5.6.160.0070.05021.14
5.6.150.0100.07320.98
5.6.140.0130.07720.97
5.6.130.0130.04321.11
5.6.120.0130.08021.05
5.6.110.0100.03320.98
5.6.100.0100.08021.03
5.6.90.0070.08321.02
5.6.80.0070.07720.48
5.6.70.0070.07320.55
5.6.60.0070.05020.39
5.6.50.0100.06320.38
5.6.40.0070.04320.57
5.6.30.0100.03320.33
5.6.20.0100.07020.35
5.6.10.0030.04320.43
5.6.00.0100.07720.40
5.5.380.0170.07020.53
5.5.370.0130.07720.41
5.5.360.0070.07720.56
5.5.350.0000.06320.46
5.5.340.0130.05020.79
5.5.330.0030.08720.95
5.5.320.0030.08020.80
5.5.310.0030.04320.90
5.5.300.0030.05020.77
5.5.290.0130.06720.91
5.5.280.0000.04720.85
5.5.270.0070.08020.93
5.5.260.0070.07720.84
5.5.250.0070.07020.77
5.5.240.0030.07720.32
5.5.230.0100.06320.32
5.5.220.0030.05020.29
5.5.210.0130.06720.25
5.5.200.0100.04020.15
5.5.190.0070.08320.21
5.5.180.0170.04020.25
5.5.160.0100.07020.31
5.5.150.0070.08320.30
5.5.140.0030.06720.24
5.5.130.0030.08020.29
5.5.120.0070.08320.23
5.5.110.0100.08020.17
5.5.100.0100.07320.14
5.5.90.0130.05720.16
5.5.80.0030.07320.15
5.5.70.0130.07720.10
5.5.60.0100.05020.18
5.5.50.0000.04320.07
5.5.40.0100.07320.06
5.5.30.0000.09020.11
5.5.20.0130.06720.04
5.5.10.0130.06720.02
5.5.00.0100.07320.00
5.4.450.0030.08719.21
5.4.440.0070.06719.55
5.4.430.0100.07319.50
5.4.420.0100.03719.41
5.4.410.0030.04719.07
5.4.400.0030.07319.12
5.4.390.0030.08019.19
5.4.380.0070.07319.05
5.4.370.0070.07319.12
5.4.360.0000.05719.16
5.4.350.0070.06719.14
5.4.340.0100.06719.03
5.4.320.0130.07319.20
5.4.310.0000.07319.06
5.4.300.0130.06319.04
5.4.290.0030.07718.84
5.4.280.0130.05319.09
5.4.270.0130.07319.12
5.4.260.0070.07718.90
5.4.250.0030.06319.22
5.4.240.0100.07718.90
5.4.230.0030.07318.93
5.4.220.0100.05719.23
5.4.210.0100.06719.12
5.4.200.0030.07719.02
5.4.190.0100.07018.89
5.4.180.0100.07018.86
5.4.170.0070.05719.20
5.4.160.0130.07318.93
5.4.150.0130.07319.14
5.4.140.0030.08716.43
5.4.130.0130.05716.41
5.4.120.0070.07316.33
5.4.110.0070.05716.54
5.4.100.0070.07016.55
5.4.90.0100.06716.55
5.4.80.0200.06016.54
5.4.70.0000.07716.43
5.4.60.0070.07316.28
5.4.50.0000.04016.45
5.4.40.0100.06716.36
5.4.30.0000.06016.48
5.4.20.0130.06316.50
5.4.10.0070.07316.33
5.4.00.0070.05715.75
5.3.290.0030.07014.64
5.3.280.0170.06014.67
5.3.270.0130.06714.68
5.3.260.0130.07014.66
5.3.250.0070.04714.63
5.3.240.0000.08314.57
5.3.230.0030.07714.59
5.3.220.0070.07714.70
5.3.210.0100.06714.63
5.3.200.0070.07714.53
5.3.190.0070.05314.62
5.3.180.0030.08014.55
5.3.170.0070.07014.57
5.3.160.0070.07714.66
5.3.150.0070.06314.67
5.3.140.0100.07014.62
5.3.130.0100.06714.58
5.3.120.0030.08714.69
5.3.110.0030.06714.60
5.3.100.0170.06314.09
5.3.90.0070.07713.99
5.3.80.0030.06013.95
5.3.70.0030.06714.12
5.3.60.0000.08314.05
5.3.50.0100.04014.11
5.3.40.0170.03314.06
5.3.30.0100.05713.96
5.3.20.0030.07013.75
5.3.10.0070.07313.71
5.3.00.0130.06713.78

preferences:
34.77 ms | 401 KiB | 5 Q