How does PHP handle communication over HTTP and the delivery of HTML pages in a logged-in state?
PHP handles communication over HTTP by using built-in functions like cURL or the HTTP extension to make requests to external servers. To deliver HTML pages in a logged-in state, PHP can use sessions to store login information and check if a user is logged in before displaying protected content.
<?php
session_start();
// Check if user is logged in
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
// Display protected content
echo "Welcome, logged in user!";
} else {
// Redirect to login page
header("Location: login.php");
exit();
}
?>
Related Questions
- What are common challenges when integrating captchas into PHP scripts?
- What is the correct order of expressions to use when combining GROUP BY and ORDER BY in PHP queries?
- What are some reliable sources for obtaining .sql files or ZIP files for importing into a database, specifically for Postleitzahlen in Deutschland?