数组序列化和反序列化

<?phpphp

  header("content-type:text/html;charset=utf-8");html

  //做用:登陆处理(验证登陆是否成功)数组

  //得到表单提交的用户名、密码ide

  $userName = $_POST["userName"];post

  $password = $_POST["password"];ui

  //得到user.txt中的用户列表信息spa

  $user = "";orm

  $handle = fopen("user.txt","r");htm

  while($str=fgets($handle))utf-8

  {

    $user .= $str;

  }

  fclose($handle);

  $userList = unserialize($user);//二维数组

  

  

?>

<?php

header("content-type:text/html;charset=utf-8");

//做用:将$userList二维数组写入user.txt文件中

$userList = array(

       array("userName"=>"hello","password"=>"123456"),

       array("userName"=>"张三","password"=>"123456"),

       array("userName"=>"tom","password"=>"123456"),

       array("userName"=>"田七","password"=>"123456")

);

$handle = fopen("user.txt","w");

fputs($handle,serialize($userList));

fclose($handle);

?>

<html>

  <head>

 <title>会员登陆</title>

<meta http-equiv="content-type" content="text/html;charset=utf-8">

    <meta charset=utf-8"/>

  </head>

  <body>

    <form  name="frm" method="post" action="check.php">

    <table  border="1" align="center">

      <tr>

        <td>登陆名称:</td>

        <td><input type="text" name="userName" size="20"></td>

      </tr>

      <tr>

        <td>登陆密码:</td>

        <td><input type="password" name="password" size="20"></td>

      </tr>

      <tr>

        <td colspan="2" align="center">

          <input  type="submit" value="登陆">

          &nbsp;&nbsp;&nbsp;

          <input  type="reset" value="重置">

          

      </tr>

    </table>

    </form>

  </body>

</html>

<?php

header("content-type:text/html;charset=utf-8");

$handle = fopen("haha.txt","r");

$str = fgets($handle);

fclose($handle);

echo  $str;

?>

相关文章
相关标签/搜索