3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Challenge: make this terrible code safe if((count($_POST) > 0) && (strlen($_POST['password']) == 0 || strlen($_POST['username']) == 0)){ echo "Please enter username and password".PHP_EOL; exit(); } try{ $pdo = new PDO('sqlite::memorytest:'); } catch(PDOException $e){ echo $e->getMessage(); } $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); $pdo->exec("DROP TABLE IF EXISTS users"); $pdo->exec("CREATE TABLE users (username VARCHAR(255), password VARCHAR(255))"); $rootPassword = password_hash("secret", PASSWORD_DEFAULT); $pdo->exec("INSERT INTO users (username, password) VALUES ('root', '$rootPassword');"); $statement = $pdo->prepare("SELECT password FROM users WHERE username = ? LIMIT 1"); if($statement->execute(array($_POST['username']))){ $row = $statement->fetchAll(); if(password_verify($_POST['password'], $row[0]['password'])){ echo "Access granted to $username!<br />\n"; exit(); } else{ echo "Access denied for $username!<br>\n"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Challenge 4</title> </head> <body> <form method="post"> <input type="text" name="username" placeholder="username" /> <input type="password" name="password" placeholder="password" /> <input type="submit" value="Submit" /> </form> </body> </html>
Output for 7.0.5 - 7.1.0
SQLSTATE[HY000] [14] unable to open database file Notice: Undefined variable: pdo in /in/1aGo0 on line 16 Fatal error: Uncaught Error: Call to a member function setAttribute() on null in /in/1aGo0:16 Stack trace: #0 {main} thrown in /in/1aGo0 on line 16
Process exited with code 255.
Output for 7.0.0 - 7.0.4
SQLSTATE[HY000] [14] unable to open database file Notice: Undefined variable: pdo in /in/1aGo0 on line 16 Fatal error: Uncaught Error: Call to a member function setAttribute() on unknown in /in/1aGo0:16 Stack trace: #0 {main} thrown in /in/1aGo0 on line 16
Process exited with code 255.
Output for 5.6.7 - 5.6.28
SQLSTATE[HY000] [14] unable to open database file Notice: Undefined variable: pdo in /in/1aGo0 on line 16 Fatal error: Call to a member function setAttribute() on null in /in/1aGo0 on line 16
Process exited with code 255.
Output for 5.1.0 - 5.1.3, 5.2.0 - 5.5.35
SQLSTATE[HY000] [14] unable to open database file Notice: Undefined variable: pdo in /in/1aGo0 on line 16 Fatal error: Call to a member function setAttribute() on a non-object in /in/1aGo0 on line 16
Process exited with code 255.
Output for 5.1.4 - 5.1.6
could not find driver Notice: Undefined variable: pdo in /in/1aGo0 on line 16 Fatal error: Call to a member function setAttribute() on a non-object in /in/1aGo0 on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Class 'PDO' not found in /in/1aGo0 on line 11
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/1aGo0 on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '{' in /in/1aGo0 on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/1aGo0 on line 10
Process exited with code 255.