不使用数据库的留言板

readme:不使用数据库的留言板
通过xml存取实现留言。(注:datafile.xml要设置为隐藏)

index.php

<?php
$pin="7407840";//设置密码
$form1="<form action='index.php' method='post'>";
$form2="密码:<input type='password' name='pin'>";
$form3="登录到:<input type='radio' name='to' value='read' checked/>读取界面"." "."<input type='radio' name='to' value='write'/>写入界面";
$form4="<input type='submit' value='提交'>"."</form>";//设置登录密码框
$action="passwithoutpin";//设置参数:跳过密码进入系统
if ($_POST['pin']===$pin || $_GET['action']===$action)
{
 if ($_REQUEST['to']==="read")
 {echo "<script>alert('已登录到读取界面')</script>";
  /*
  以下为读取界面主要代码
  */
  echo "<br/>";
  $datafile=fopen("datafile.xml","r");
$filedata=fread($datafile,4096);
   if (!$datafile)
   {
    echo "错误:无法打开文件!"."<br/>"."联系站长!";
    die();
   }//以"read"模式打开文件
  $parser=xml_parser_create();//开始解析xml文件
  if (!xml_parse_into_struct($parser,$filedata,$data))
  {
   echo "错误:".xml_error_string(xml_error_code($parser))."<br/>";
   echo "当前行:".xml_get_current_line_number($parser)."<br/>";
   echo "当前列:".xml_get_current_column_number($parser);
   die();
  }
  else
  {
   xml_parser_free($parser);
  }
  echo "<h3>留言条目</h3>";
  echo "<br/>".$data[0]['tag'];
  echo "<br/>".$data[1]['tag'].":".$data[1]['value'];
  echo "<br/>".$data[3]['tag'].":".$data[3]['value'];
  echo "<br/>".$data[5]['tag'].":".$data[5]['value'];
  echo "<br/>".$data[7]['tag'].":".$data[7]['value'];
  fclose($datafile);
 }
 elseif ($_REQUEST['to']==="write")
 {
  echo "<script>alert('已登录到写入界面')</script>";
  /*以下为写入界面主要代码
  */
  echo "<br/>";
  echo "<h3>新建新留言</h3>";
  echo "<form action='write.php' method='post'>";
  echo "留言类型:<input type='radio' name='type' value='任务'>任务";
  echo "<input type='radio' name='type' value='提醒'>提醒";
  echo "<input type='radio' name='type' value='信息'>信息"."<br/>";
  echo "日期:<input type='text' name='date'/>"."<br/>";
  echo "任务:<input type='text' name='todo'/>"."<br/>";
  echo "位置:<input type='text' name='loc'/>"."<br/>";
  echo "标签:<input type='text' name='lab'/>"."<br/>";
  echo "<input type='submit' value='提交'>";
  echo "</form>";
 }
}
elseif ($_POST['password'] != $pin && isset($_POST['password']))
{
echo "密码错误!";
}
else
{
echo $form1."<br/>".$form2."<br/>".$form3."<br/>".$form4;
echo "请输入密码!";
}
?>

write.php

<?php
//先确认,再写入
$reminder=
    "<script>
    if (!confirm('确定要继续,将会覆盖原来的留言内容!点击取消返回。'))
    {
    history.go(-2);
    }
    </script>";
//打开文件
$datafile=fopen("datafile.xml","w");
if (!$datafile)
{
 echo "错误:无法打开文件!"."<br/>"."联系站长!";
 die();
}
else
{
 $contents=
 "<?xml version='1.0' encoding='ISO-8859-1 ?>
 <{$_POST['type']}>
 <日期>{$_POST['date']}</日期>
 <任务>{$_POST['todo']}</任务>
 <位置>{$_POST['loc']}</位置>
 <标签>{$_POST['lab']}</标签>
 <{$_POST['type']}>
 ";
  if (!file_put_contents(datafile.xml,$contents))
  {
   echo "错误:无法写入文件!"."<br/>"."联系站长!";
   die();
  }
$return=
 "<script>
 alert('写入文件成功,点击确认键返回!');
 history.go(-2);
 </script>
 ";
echo $return;
}
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值