Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- access cookie
- <?php
- // Check if the cookie is set
- if (isset($_COOKIE["username"])) {
- echo "Welcome back, " . $_COOKIE["username"] . "!";
- } else {
- echo "No cookie found. Please log in.";
- }
- ?>
- cookie example
- <?php
- // Set a cookie that lasts for 1 hour
- setcookie("username", "JohnDoe", time() + 3600, "/"); // "/" makes it available across the whole domain
- echo "Cookie has been set.";
- ?>
- <?php
- // Delete the cookie by setting its expiration date to the past
- setcookie("username", "", time() - 3600, "/");
- echo "Cookie has been deleted.";
- ?>
- session example
- <?php
- // Start the session session_start();
- // Store session variables
- $_SESSION["username"] = "JohnDoe";
- $_SESSION["email"] = "johndoe@example.com"; echo "Session variables are set.";
- ?>
- active session
- <?php
- // Start the session session_start();
- // Store session variables
- $_SESSION["username"] = "JohnDoe";
- $_SESSION["email"] = "johndoe@example.com"; echo "Session variables are set.";
- ?>
- destroy session
- <?php
- // Start the session session_start();
- // Remove all session variables session_unset();
- // Destroy the session
- session_destroy();
- echo "Session destroyed. You have been logged out.";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement