note 129963 added to reserved.variables.session

From: Date: Fri, 10 Jan 2025 11:15:52 +0000
Subject: note 129963 added to reserved.variables.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-221776@lists.php.net to get a copy of this message
<?php !-! login.php session_start(); $servername = "mysql2"; $username = "root"; $password = "htlkrems"; try { $conn = new PDO("mysql:host=$servername;dbname=test_php_db", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { die("Connection failed: " . $e->getMessage()); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $stmt = $conn->prepare("SELECT * FROM users WHERE username = :username AND password = :password"); $stmt->bindParam(':username', $_POST['username']); $stmt->bindParam(':password', $_POST['password']); // Hash Passwort hier in der Praxis! $stmt->execute(); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ($user) { $_SESSION['user_id'] = $user['id']; header("Location: index.php"); exit(); } else { $error = "Invalid username or password!"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> <title>Login</title> </head> <body class="container"> <div class="row justify-content-center mt-5"> <div class="col-md-4"> <h2>Login</h2> <?php if (isset($error)) { echo '<div class="alert alert-danger">' . $error . '</div>'; } ?> <form method="post"> <div class="mb-3"> <label for="username" class="form-label">Username</label> <input type="text" class="form-control" id="username" name="username" required> </div> <div class="mb-3"> <label for="password" class="form-label">Password</label> <input type="password" class="form-control" id="password" name="password" required> </div> <button type="submit" class="btn btn-primary">Login</button> </form> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> </body> </html> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 193.170.70.27) ---- Manual Page -- https://php.net/manual/en/reserved.variables.session.php Edit -- https://main.php.net/note/edit/129963 Del: integrated -- https://main.php.net/note/delete/129963/integrated Del: useless -- https://main.php.net/note/delete/129963/useless Del: bad code -- https://main.php.net/note/delete/129963/bad+code Del: spam -- https://main.php.net/note/delete/129963/spam Del: non-english -- https://main.php.net/note/delete/129963/non-english Del: in docs -- https://main.php.net/note/delete/129963/in+docs Del: other reasons-- https://main.php.net/note/delete/129963 Reject -- https://main.php.net/note/reject/129963 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221776) next »