PHPPHP实战

session实现不同页面间传递数据

2016-12-28  本文已影响508人  MakingChoice

数据在index.php和i.php之间通信
index.php

session_set_cookie_params($_POST("check"));
session_start();
if($_POST[sub]){
    if($_POST['user']!="" && $_POST("pwd")!=""){
          if($_POST['user']==="mr" && $_POST("pwd")==="miscrof"){
                  $_SESSION['user']=$_POST["user"];
                  $_SEESION['pwd']=$_POST["pwd"];
                  $_SESSION['check']=$_POST["check"]
                  echo"<script>alert("管理员登录正确");window.location.href="i.php"<script>"
          }else{
                  echo"<script>alert("密码正确");window.location.href="index.php"</script>"
          }
    }else{
            echo"<script>alert("用户名、密码不能为空");window.lcation.href="index.php"</script>"
     }
}

i.php

session_start();
echo"当前时间".data('Y-m-d')."<br>";
echo"用户名".$_SESSION["user"]."<br>";
echo"密码".$_SESSION['pwd']."<br>";
echo"实效".$_SESSION['check']."<br>";
echo "<a href="logout.php">退出</a>"

logout.php
···
session_start();
session_destroy();
echo"<script>alert("退出");window.location.href="index.php"<script>"
···

上一篇 下一篇

猜你喜欢

热点阅读