zoukankan      html  css  js  c++  java
  • Cookie

    A cookie is often used to identify a user.A cookie is a small file that the server embeds on the user's computer.Each time the same computer requests a page with a browser, it will send the cookie too.

    A cookie is created with the setcookie() function

    setcookie(name, value, expire, path, domain, secure, )

    <!-- The setcookie() function must appear BEFORE the <html> tag -->

    <?php
    $cookie_name = "user";
    $cookie_value = "John Doe";
    setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
    ?>  

    <html>
    <body>

    <?php
    if(!isset($_COOKIE[$cookie_name])) {
        echo "Cookie named '" . $cookie_name . "' is not set!";
    } else {
        echo "Cookie '" . $cookie_name . "' is set!<br>";
        echo "Value is: " . $_COOKIE[$cookie_name];
    }
    ?>

    </body>
    </html>

    <!-- modify a cookie value -->

    <?php
    $cookie_name = "user";
    $cookie_value = "Alex Porter";
    setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
    ?>
    <html>
    <body>

    <?php
    if(!isset($_COOKIE[$cookie_name])) {
        echo "Cookie named '" . $cookie_name . "' is not set!";
    } else {
        echo "Cookie '" . $cookie_name . "' is set!<br>";
        echo "Value is: " . $_COOKIE[$cookie_name];
    }
    ?>

    </body>
    </html>

    <!-- delete a cookie -->

    <?php
    // set the expiration date to one hour ago
    setcookie("user", "", time() - 3600);
    ?>
    <html>
    <body>

    <?php
    echo "Cookie 'user' is deleted.";
    ?>

    </body>
    </html>

  • 相关阅读:
    [PY3]——logging
    [PY3]——对iterator的处理(解析式、map、reduce、filter)
    php基础语法(文件加载和错误)
    php基础语法(控制语句、数组、函数)
    php基础语法(数据类型、运算符)
    php基础语法(变量)
    java基础语法
    ztree 获取根节点
    每天一个linux命令
    浅谈Web自适应
  • 原文地址:https://www.cnblogs.com/forerver-elf/p/5201893.html
Copyright © 2011-2022 走看看