3v4l.org

run code in 300+ PHP versions simultaneously
<?php function random_password( $length = 8 ) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?"; $password = substr( str_shuffle( $chars ), 0, $length ); return $password; } $error = ""; if (isset($_GET["token"]) && preg_match('/^[0-9A-F]{40}$/i', $_GET["token"])) { $token = $_GET["token"]; define("DB_HOST","mysql117.loopia.se"); define("DB_USER","normal@i103189"); define("DB_PASS","KungMicke87"); define("DB_NAME","indiehjaerta_com"); // Connect to MySQLi $sqli = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die("Error: ".mysqli_error($sqli)); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $query = mysqli_query($sqli, "SELECT * FROM passwordrequest WHERE token='$token'") or die("Error: ".mysqli_error($sqli)); $results = mysqli_num_rows($query); if ($results == 0) { $error = "Error invalid token."; } else { $row = mysqli_fetch_array($query); $email = $row['email']; $timestamp = $row['timestamp']; $url = "http://www.indihjaerta.com/login.php"; //Generate Password Here -- FIXA!!!!!!!!! $password = random_password(8); echo $password; //Has Password Here $hashedpassword = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]); //Update new password in table $updatequery = mysqli_query($sqli,"UPDATE members SET password = '$hashedpassword' WHERE email='$email'"); //$message = "Press think link $url to reset your password.\n\n If you didn't request a password change please discard this e-mail."; $message = "This function is currently not working :(. But it should be a password here." $headers = 'From: [indiehjaerta.com] Admin <no-reply@indiehjaerta.com>' . "\r\n"; mail($email, "[indiehjaerta.com] New Password", $message, $headers); //Delete post to make link invalid $deletequery = mysqli_query($sqli, "DELETE * FROM passwordrequest WHERE token='$token' AND email='$email' AND timestamp='$timestamp'") or die("Error: ".mysqli_error($sqli)); } } else { $error = "No token." } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>indiehjaerta.com</title> <link href="style_test.css" rel="stylesheet" type="text/css" /> </head> <body> <a href="login.php">Login<a/> - <a href="admin.php">Admin<a/> - <a href="members.php">Members<a/> - <a href="register.php">Register<a/> - <a href="blog.php">Blog<a/> - <a href="news.php">News<a/> - <a href="event.php">Event<a/> - <a href="forum.php">Forum<a/> <br /> <br /> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <?php if (!empty($error)) { ?> <td colspan="3"><strong><?php echo $error ?></strong></td> <?php } else { ?> <td colspan="3"><strong>Not implemented. <!-- An e-mail containing your new password has been sent to e-mail . --></strong></td> <?php } ?> </tr> </table> </td> </tr> </table> </body> </html>
Output for 5.4.0 - 5.4.43, 5.5.24 - 5.5.26, 5.6.8 - 5.6.10
Parse error: syntax error, unexpected '$headers' (T_VARIABLE) in /in/HeUbS on line 56
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/HeUbS on line 48
Process exited with code 255.

preferences:
189.8 ms | 1395 KiB | 86 Q