<?php
    function set_my_cookie($var, $value = '', $time = 0, $path = '', $domain = '') {
        $_COOKIE[$var] = $value;
        setcookie($var, $value, $time, $path, $domain);
    }
    // set_my_cookie('test', 'ryan_test');
    // echo $_COOKIE['test'];
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        set_my_cookie('test1', 'ryan_test1');
    }
    echo $_COOKIE['test1'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Cookie</title>
</head>
<body>
    <form action="" method='post'>
        <input type="submit" />
    </form>
</body>
</html>

 

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2021-11-10
  • 2021-08-20
猜你喜欢
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-08-08
  • 2021-11-29
相关资源
相似解决方案