Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----- arquivo definido.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Meu Site com Tema</title>
- <?php
- // Verifica se o cookie de tema foi definido
- if (isset($_COOKIE['theme'])) {
- $theme = $_COOKIE['theme'];
- // Carrega um arquivo CSS com base no tema escolhido
- echo '<link rel="stylesheet" href="' . $theme . '_theme.css">';
- }
- ?>
- </head>
- <body>
- <h1>Bem-vindo ao Meu Site</h1>
- <p>Este é um exemplo de site que usa cookies para lembrar o tema de cor escolhido.</p>
- <p><a href="preferences.php">Configurar Preferências</a></p>
- </body>
- </html>
- ----- arquivo preferences.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Preferências de Tema</title>
- </head>
- <body>
- <h1>Preferências de Tema</h1>
- <form action="set_cookie.php" method="post">
- <label for="theme">Escolha um tema de cor:</label>
- <select name="theme" id="theme">
- <option value="light">Claro</option>
- <option value="dark">Escuro</option>
- </select>
- <br>
- <input type="submit" value="Salvar Preferência">
- </form>
- </body>
- </html>
- --- arquivo set_cookie.php
- <?php
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- if (isset($_POST['theme'])) {
- $theme = $_POST['theme'];
- // Define um cookie com o tema escolhido que expira em 30 dias
- setcookie('theme', $theme, time()+3600, '/');
- }
- }
- header('Location: definido.php'); // Redireciona de volta para a página inicial
- ?>
- ---
- ------ arquivo dark_theme.css
- body {
- background-color: #333;
- color: #fff;
- }
- h1 {
- color: #eee;
- }
- a {
- color: #66b3ff;
- }
- ---------- arquivo light_theme.css
- body {
- background-color: #f5f5f5;
- color: #333;
- }
- h1 {
- color: #555;
- }
- a {
- color: #007bff;
- }
Advertisement
Add Comment
Please, Sign In to add comment