i want a php website that can save input password in session variable and echo it out
Sure! Here's an example of a PHP website that saves an input password in a session variable and echoes it out:
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$password = $_POST['password'];
$_SESSION['password'] = $password;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Password Storage</title>
</head>
<body>
<?php if (isset($_SESSION['password'])): ?>
<h2>Password: <?php echo $_SESSION['password']; ?></h2>
<?php endif; ?>
<form method="POST" action="">
<label for="password">Enter Password:</label>
<input type="password" name="password" id="password">
<button type="submit">Submit</button>
</form>
</body>
</html>
In this example, the password entered in the input field is stored in the $_SESSION['password'] variable when the form is submitted. When the page is reloaded or revisited, if the session variable is set, it will be echoed out in the <h2> tag.
Note: Storing passwords in session variables is not recommended for security reasons. This example is just for demonstration purposes. In a real-world scenario, you should use proper password hashing and secure storage methods
原文地址: https://www.cveoy.top/t/topic/hGOU 著作权归作者所有。请勿转载和采集!