• 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>

  • 相关阅读:
    SQL Server数据库中批量导入数据
    SQL里面也能用Split()
    MSSQL发送邮件
    Asp.Net简单的发邮件功能
    十大措施保证系统安全性
    WebDriver测试web中遇到的弹出框或不确定的页面
    WebDriver数据驱动模式
    nginx 优化(转)
    配置虚拟目录出错
    14152学期校内岗招聘信息
  • 原文地址:https://www.cnblogs.com/forerver-elf/p/5201893.html
Copyright © 2020-2023  润新知