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>

  • 相关阅读:
    把word文档转换成swf格式
    利用“审阅”批改作业
    注意:QQ空间加密并不安全
    MySQLDB 错误 InterfaceError(0,")
    Linux 文件大小 文件夹大小 磁盘大小
    JavaArrays类fill()方法详解
    构造函数
    ASP部署错误"未能加载类型..."
    试AJAX出错两则
    ASP.Net如何区分开发状态与实际应用状态
  • 原文地址:https://www.cnblogs.com/forerver-elf/p/5201893.html
Copyright © 2011-2022 走看看