3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Challenge: make this terrible code safe // echo "<!doctype html>\n"; $_GET['username'] = 'foo'; $_GET['password'] = 'bar'; $username = @$_GET['username'] ? $_GET['username'] : $argv[1]; $password = @$_GET['password'] ? $_GET['password'] : $argv[2]; $password = md5($password); $pdo = new PDO('sqlite::memory:'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec("DROP TABLE IF EXISTS users"); $pdo->exec("CREATE TABLE users (username VARCHAR(255), password VARCHAR(255))"); $rootPassword = md5("secret"); $pdo->exec("INSERT INTO users (username, password) VALUES ('root', '$rootPassword');"); $statement = $pdo->query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"); if (count($statement->fetchAll())) { echo "Access granted to $username!<br>\n"; } else { echo "Access denied for $username!<br>\n"; }
based on egQJu
Output for 5.2.0 - 7.2.0
Access denied for foo!<br>
Output for 5.1.4 - 5.1.6
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /in/DLi9V:13 Stack trace: #0 /in/DLi9V(13): PDO->__construct('sqlite::memory:') #1 {main} thrown in /in/DLi9V on line 13
Process exited with code 255.
Output for 5.1.0 - 5.1.3
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 near "EXISTS": syntax error' in /in/DLi9V:16 Stack trace: #0 /in/DLi9V(16): PDO->exec('DROP TABLE IF E...') #1 {main} thrown in /in/DLi9V on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Class 'PDO' not found in /in/DLi9V on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected ',', expecting '(' in /in/DLi9V on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected ',', expecting '(' in /in/DLi9V on line 14
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'('' in /in/DLi9V on line 14
Process exited with code 255.