3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Challenge: make this terrible code safe echo "<!doctype html>\n"; /* ALWAYS make sure to use PHP 5.5.0+ */ if (version_compare(PHP_VERSION, '5.5.0', '<')) { echo "You are using PHP " . PHP_VERSION . ". Please update to PHP 5.5.0 or higher."; exit; } $_GET['username'] = 'mayur'; $_GET['password'] = '12346'; $username = (!empty($_GET['username'])) ? : ((!empty($argv[1])) ? : null); $password = (!empty($_GET['password'])) ? : ((!empty($argv[2])) ? : null); if (empty($username) || empty($password)) { echo "No Username/Password Found!"; exit; } /** * While creating a new User we use password_hash() method to * generate a SALT+HASH string and store it * e.g. * $password = password_hash($password, PASSWORD_DEFAULT); */ try { $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))"); /* Set ROOT password (SALT+HASH) */ $rootPassword = password_hash("secret", PASSWORD_DEFAULT); $data = ['username' => 'root', 'password' => $rootPassword]; $query = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)"); $query->bindValue(':username', $data['username'], PDO::PARAM_STR); $query->bindValue(':password', $data['password'], PDO::PARAM_STR); $query->execute(); /* Select Data */ $statement = $pdo->prepare("SELECT * FROM users WHERE username = :username LIMIT 1"); $statement->bindValue(':username', $username, PDO::PARAM_STR); $statement->execute(); $user = $statement->fetch(PDO::FETCH_ASSOC); // Get the single ROW /** * Verify the password using supplied string & stored SALT+HASH * password_verify(supplied, stored) */ if (!empty($user) && password_verify($password, $user['password'])) { echo "Access granted to $username!<br>\n"; } else { echo "Access denied for $username!<br>\n"; } } catch (PDOException $e) { // Print PDOException message echo $e->getMessage(); }
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.17 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
<!doctype html> Access denied for 1!<br>
Output for 5.4.45
<!doctype html> You are using PHP 5.4.45. Please update to PHP 5.5.0 or higher.
Output for 5.4.44
<!doctype html> You are using PHP 5.4.44. Please update to PHP 5.5.0 or higher.
Output for 5.4.43
<!doctype html> You are using PHP 5.4.43. Please update to PHP 5.5.0 or higher.
Output for 5.4.42
<!doctype html> You are using PHP 5.4.42. Please update to PHP 5.5.0 or higher.
Output for 5.4.41
<!doctype html> You are using PHP 5.4.41. Please update to PHP 5.5.0 or higher.
Output for 5.4.40
<!doctype html> You are using PHP 5.4.40. Please update to PHP 5.5.0 or higher.
Output for 5.4.39
<!doctype html> You are using PHP 5.4.39. Please update to PHP 5.5.0 or higher.
Output for 5.4.38
<!doctype html> You are using PHP 5.4.38. Please update to PHP 5.5.0 or higher.
Output for 5.4.37
<!doctype html> You are using PHP 5.4.37. Please update to PHP 5.5.0 or higher.
Output for 5.4.36
<!doctype html> You are using PHP 5.4.36. Please update to PHP 5.5.0 or higher.
Output for 5.4.35
<!doctype html> You are using PHP 5.4.35. Please update to PHP 5.5.0 or higher.
Output for 5.4.34
<!doctype html> You are using PHP 5.4.34. Please update to PHP 5.5.0 or higher.
Output for 5.4.32
<!doctype html> You are using PHP 5.4.32. Please update to PHP 5.5.0 or higher.
Output for 5.4.31
<!doctype html> You are using PHP 5.4.31. Please update to PHP 5.5.0 or higher.
Output for 5.4.30
<!doctype html> You are using PHP 5.4.30. Please update to PHP 5.5.0 or higher.
Output for 5.4.29
<!doctype html> You are using PHP 5.4.29. Please update to PHP 5.5.0 or higher.
Output for 5.4.28
<!doctype html> You are using PHP 5.4.28. Please update to PHP 5.5.0 or higher.
Output for 5.4.27
<!doctype html> You are using PHP 5.4.27. Please update to PHP 5.5.0 or higher.
Output for 5.4.26
<!doctype html> You are using PHP 5.4.26. Please update to PHP 5.5.0 or higher.
Output for 5.4.25
<!doctype html> You are using PHP 5.4.25. Please update to PHP 5.5.0 or higher.
Output for 5.4.24
<!doctype html> You are using PHP 5.4.24. Please update to PHP 5.5.0 or higher.
Output for 5.4.23
<!doctype html> You are using PHP 5.4.23. Please update to PHP 5.5.0 or higher.
Output for 5.4.22
<!doctype html> You are using PHP 5.4.22. Please update to PHP 5.5.0 or higher.
Output for 5.4.21
<!doctype html> You are using PHP 5.4.21. Please update to PHP 5.5.0 or higher.
Output for 5.4.20
<!doctype html> You are using PHP 5.4.20. Please update to PHP 5.5.0 or higher.
Output for 5.4.19
<!doctype html> You are using PHP 5.4.19. Please update to PHP 5.5.0 or higher.
Output for 5.4.18
<!doctype html> You are using PHP 5.4.18. Please update to PHP 5.5.0 or higher.
Output for 5.4.17
<!doctype html> You are using PHP 5.4.17. Please update to PHP 5.5.0 or higher.
Output for 5.4.16
<!doctype html> You are using PHP 5.4.16. Please update to PHP 5.5.0 or higher.
Output for 5.4.15
<!doctype html> You are using PHP 5.4.15. Please update to PHP 5.5.0 or higher.
Output for 5.4.14
<!doctype html> You are using PHP 5.4.14. Please update to PHP 5.5.0 or higher.
Output for 5.4.13
<!doctype html> You are using PHP 5.4.13. Please update to PHP 5.5.0 or higher.
Output for 5.4.12
<!doctype html> You are using PHP 5.4.12. Please update to PHP 5.5.0 or higher.
Output for 5.4.11
<!doctype html> You are using PHP 5.4.11. Please update to PHP 5.5.0 or higher.
Output for 5.4.10
<!doctype html> You are using PHP 5.4.10. Please update to PHP 5.5.0 or higher.
Output for 5.4.9
<!doctype html> You are using PHP 5.4.9. Please update to PHP 5.5.0 or higher.
Output for 5.4.8
<!doctype html> You are using PHP 5.4.8. Please update to PHP 5.5.0 or higher.
Output for 5.4.7
<!doctype html> You are using PHP 5.4.7. Please update to PHP 5.5.0 or higher.
Output for 5.4.6
<!doctype html> You are using PHP 5.4.6. Please update to PHP 5.5.0 or higher.
Output for 5.4.5
<!doctype html> You are using PHP 5.4.5. Please update to PHP 5.5.0 or higher.
Output for 5.4.4
<!doctype html> You are using PHP 5.4.4. Please update to PHP 5.5.0 or higher.
Output for 5.4.3
<!doctype html> You are using PHP 5.4.3. Please update to PHP 5.5.0 or higher.
Output for 5.4.2
<!doctype html> You are using PHP 5.4.2. Please update to PHP 5.5.0 or higher.
Output for 5.4.1
<!doctype html> You are using PHP 5.4.1. Please update to PHP 5.5.0 or higher.
Output for 5.4.0
<!doctype html> You are using PHP 5.4.0. Please update to PHP 5.5.0 or higher.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Iq37N on line 39
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/Iq37N on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':' in /in/Iq37N on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Iq37N on line 16
Process exited with code 255.

preferences:
172.57 ms | 401 KiB | 205 Q