1. 程式人生 > >PHP寫登入頁面與退出頁面

PHP寫登入頁面與退出頁面

 <?php
   include("../com/conn.php");
   if($_POST[sub]){
      $sql ="select * from cp_userlist where username='".$_POST[user]."' and password='".$_POST[pwd]."'";
      $query=mysql_query($sql);
      $row = mysql_fetch_array($query);
      if($row){
          $_SESSION["name"]=$_POST[user];
          echo "<script>window.location.href='http://wyl072.blog.163.com/blog/index.php';</script>";
      }
      else {
          echo "<script>alert(\"使用者名稱或者密碼錯誤!\");</script>";
          echo "<script>window.location.href='http://wyl072.blog.163.com/blog/login.php'</script>";
      }
   } else { 
   }
   ?>

 <form action="login.php" method="post">
   使用者名稱稱:<input name="user" type="text"  /><br />
   使用者密碼:<input name="pwd" type="password" /><br />
   <input type="submit" name="sub" value="登入"/><input type="reset" value="重置" />
 </form>