Romarain

setcookie test page

Sep 11th, 2025 (edited)
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.58 KB | None | 0 0
  1. <?php /* ------------ PHP COMMON OPERATIONS ------------ */
  2.     $max_expiration = time() + 34560000; // (400 * 24 * 60 * 60) = 34560000
  3.     // $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
  4.     $cookie_options = array('expires' => $max_expiration, 'path' => '/', 'domain' => '', 'secure' => false, 'httponly' => false, 'samesite' => 'None');
  5.     // $cookie_options = array('expires' => $max_expiration, 'path' => '/', 'domain' => '', 'secure' => false, 'httponly' => false);
  6.     $cookie_options_string = json_encode($cookie_options);
  7.     // $cookie_options_decoded = json_decode($cookie_options_string, true); // I keep that as an exemple to how re-obtain the original array.
  8.     $cookie_value = array(
  9.         'options' => $cookie_options_string, /* Jesus... */
  10.         'répondu' => false
  11.     );
  12.     $cookie_value_string = json_encode($cookie_value);
  13.     // setcookie("Sondage01", $cookie_value_string, $cookie_options);
  14.     // $cookie_created = setcookie("Sondage01", $cookie_value_string, $cookie_options);
  15.     // $cookie_created = setcookie("Sondage01", $cookie_value_string, $max_expiration, '/', '', false, false);
  16.     try {
  17.         setcookie("Sondage01", $cookie_value_string, $cookie_options);
  18.         // setcookie("Sondage01", $cookie_value_string, $max_expiration, '/', '', false, false);
  19.         $cookie_return = "Ca semble bon";
  20.         //$_COOKIE["Sondage01"] = $cookie_value_string;
  21.        
  22.     } catch(Exception $e) {
  23.         // echo "<section>";
  24.         // echo "<p>Impossible d'écrire le cookie.</p>";
  25.         // echo "<p>".$e->getMessage()."</p>";
  26.         // echo "</section>";
  27.     }
  28.     /* ------------------------------------------------- */
  29. ?>
  30. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
  31.  
  32. <html class="home" style="background-color: #0C051D;">
  33.  
  34.     <head>
  35.         <meta charset="utf-8">
  36.         <title>TEST</title>
  37.         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  38.     </head>
  39.  
  40.     <body id="top" class="header_scrolled">
  41.  
  42.         <div id="over_content">
  43.             <?php echo "<p>max_expiration : $max_expiration</p>"; ?>
  44.             <?php echo "<p>cookie_options_string : $cookie_options_string</p>"; ?>
  45.             <?php echo "<p>Cookie creation : $cookie_return</p>"; ?>
  46.             <?php echo "<p>COOKIE content : ".$_COOKIE["Sondage01"]."</p>"; ?>
  47.         </div>
  48.  
  49.         <div class="content">
  50.        
  51.             <div class="wrapper">
  52.                
  53.                 <main>
  54.                     <section>
  55.                         <h1>Page de test</h1>
  56.                         <p>Hello world.</p>
  57.                     </section>
  58.                 </main>
  59.                
  60.             </div> <!-- Wrapper -->
  61.            
  62.             <footer id="main_footer" class="main">
  63.             </footer>
  64.            
  65.             <div class="behind_content">
  66.             </div><!-- .behind_content -->
  67.        
  68.         </div><!-- .content -->
  69.    
  70.     </body>
  71.    
  72. </html>
  73.  
Advertisement
Add Comment
Please, Sign In to add comment