note 129239 added to reserved.variables.server
| From: | forexample dot com at main dot php dot net | Date: | Tue, 13 Feb 2024 01:22:08 +0000 |
| Subject: | note 129239 added to reserved.variables.server | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221192@lists.php.net to get a copy of this message | ||
<!-- login.php -->
<?php
session_start();
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check if username and password are provided
if (!empty($_POST["username"]) && !empty($_POST["password"])) {
// Assuming user authentication logic here (e.g., checking against a database)
$username = $_POST["username"];
$password = $_POST["password"];
// Here, you would typically check the username and password against a database
// For this example, let's assume a hardcoded username and password
$valid_username = "admin";
$valid_password = "password123";
if ($username === $valid_username && $password === $valid_password) {
// Authentication successful, set session variables
$_SESSION["loggedin"] = true;
$_SESSION["username"] = $username;
// Redirect to a secure page after successful login
header("location: welcome.php");
exit;
} else {
// Invalid username or password
$error = "Invalid username or password";
}
} else {
// Username or password is empty
$error = "Username and password are required";
}
}
?>
<!-- welcome.php -->
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
// Redirect to login page if not logged in
header("location: login.html");
exit;
}
// Display welcome message
echo "<h2>Welcome, " . $_SESSION["username"] . "!</h2>";
echo "<p>This is a secure page.</p>";
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 163.53.144.87)
----
Manual Page -- https://php.net/manual/en/reserved.variables.server.php
Edit -- https://main.php.net/note/edit/129239
Del: integrated -- https://main.php.net/note/delete/129239/integrated
Del: useless -- https://main.php.net/note/delete/129239/useless
Del: bad code -- https://main.php.net/note/delete/129239/bad+code
Del: spam -- https://main.php.net/note/delete/129239/spam
Del: non-english -- https://main.php.net/note/delete/129239/non-english
Del: in docs -- https://main.php.net/note/delete/129239/in+docs
Del: other reasons-- https://main.php.net/note/delete/129239
Reject -- https://main.php.net/note/reject/129239
Search -- https://main.php.net/manage/user-notes.php