zoukankan      html  css  js  c++  java
  • 会话控制

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <?php
    session_start();
    /*
    //存储SESSION信息
    $_SESSION["uid"] = "123";
    $_SESSION["name"] = "张三";
    
    echo $_SESSION["uid"];*/
    
    //Session
    //1.存储在服务器
    //2.可以存放任何类型的数据
    //3.有默认过期时间15分钟
    //4.每个登陆者都会存一份
    
    //Session用法:
    //1.可以用来在页面之间传值
    //登录传用户名,购物车,流程
    //2.可以记录登录者的状态
    //3.可以防止用户跳过登录
    
    
    //Cookie
    //1.存储在客户端
    //2.只能存放字符串
    //3.默认永久的,可以设置过期时间
    //4.每个登陆者都会存一份
    
    ?>
    </body>
    </html>

    登录程序

    加了session,防止直接输入网址访问登录后的页面

    一、denglu.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <form action="chuli.php" method="post">
    <div>用户名:<input type="text" name="uid"/></div>
    <div>密码:<input type="text" name="pwd"/></div>
    <div><input type="submit" value="登录"/></div>
    </form>
    </body>
    </html>

    二、

    <?php
    //session_start();
    
    $uid = $_POST["uid"];
    
    //中间查询数据库,判断用户名密码是否匹配
    //如果匹配
    //$_SESSION["uid"] = $uid;<br>
    
    //Cookie存储信息
    setcookie("uid",$uid);
    
    header("Location:main.php");

    三、登陆后的页面main.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <?Php
    //session_start();
    
    //防止用户跳过登录页面
    /*if(empty($_SESSION["uid"]))
    {
        header("Location:denglu.php");
    }*/
    
    
    //echo $_SESSION["uid"];
    
    echo $_COOKIE["uid"];
    
    ?>
    </body>
    </html>

    chuli.php

  • 相关阅读:
    安装virtualbox后无法上网
    win8 添加语言现象 (中英文切换路径)
    pre-condition & post-condition
    win8系统 host process for windows tasks has stopped working
    Chrome一直提醒要翻译网页
    百度首页导航设置
    停止windows8自动下载更新系统
    win8 添加开机启动项 (类似win7系统中开始->选择要启动的程序)
    扩展欧几里得定理
    UVA1583-Digit Generator(紫书例题3.5)
  • 原文地址:https://www.cnblogs.com/zhanghaozhe8462/p/5427435.html
Copyright © 2011-2022 走看看