您的位置:首页 > 编程语言 > PHP开发

PHP学习之简单应用(1)

2014-08-01 11:12 218 查看
改进主页面menu.html如下:

 1 <html><head>

  2     <title>简单的留言板</title>

  3 </head><body>

  4 <p><h3 align = "center"><font color = "red">欢迎来的我的简单留言板,请登录或

    者注册。</font></h3></p>

  5 <form action = "log.php" method = "post">

  6 Username:<input type = "text" name = "username" />

  7 Passwd:<input type  = "password" name = "password" maxlength = "6" /><br>

  8 <input type = "submit" /> <input type = "reset" /><br> <F12><a href = "    reg.php">如果没有帐号,点击这里注册吧!</a>

  9 </body></html>

其中文件reg.php内容如下:

  1 <html><head>

  2 <title>注册网页</title></head><body>

  3 <form action = "in.php" method = "post" >

  4 <br>用户名:   <input type = "text" name = "username" id = "username"/>

  5 <br>密码:      <input type = "password" name = "password" id = "password"/>

  6 <br>确认密码:<input type = "password" name = "password1" id = "password1"/>

  7 <br><input type = "submit" value = "提交" name = "submit" onclick = "cklogin();return false;" />

  8 </form>

  9 <script>

 10     function cklogin(){

 11         var username =document.getElementById('username');

 12         var passwd=document.getElementById('password');

 13         var passwd1 = document.getElementById('password1');

 14         if(username.value =="" || passwd.value==""){

 15             alert("用户名或者密码不能为空");

 16         }else if(passwd.value != passwd1.value){

 17             alert("您两次输入的密码不一致,请重新输入。");

 18         }else{

 19             this.document.FORM.submit();

 20         }

 21     }

 22 </script>

 23 </body></html>

其中in.php文件内容如下:

  1 <html><body><?php

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

  3     if(file_exists("info/info.txt"))

  4         $str = "\n".$_POST["username"]."*".$_POST["password"];

  5     else{

  6         $str =  $_POST["username"]."*".$_POST["password"];

  7     }

  8     $file = fopen("info/info.txt","ab");

  9     fwrite($file,$str);

 10     print "您已经成功注册,请返回登录吧。";

 11     fclose($file);

 12 ?><a href = "menu.html"><br>点击登录</a></body></html>

未完待续。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: