Administrator login for developing simple guestbook in PHP
We will use jquery in this section. First we need to introduce a jquery library, as follows:
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> 写入代码 </script>
Here we introduce the jquery library: "http://libs.baidu.com/jquery/ 1.7.2/jquery.min.js”
The administrator login uses click on the <input> tag to display and hide the login window.
Use the jquery toggle() method to switch the visible state of an element.
If the selected elements are visible, then hide these elements. If the selected elements are hidden, then display these elements.
Add an id="login_show_button
<div class="login_button"><a href="#" id="login_show_button">管理员登录</a></div>
to the <a> tag when logged in by the administrator
<script type="text/javascript"> $(document).ready(function() { $("#login_show_button").toggle(function(){ $("#login_form").show(100); return false; },function(){ $("#login_form").hide(100); return false; }); </script>
Then use the following jquery code to achieve the effect
<?php class User{ static public function validate($username,$password){ // static public 声明公共变量 if("admin"==$username && "12345"==$password){ return true; } else return false; } } ?>
show() representation Show, hide() means hide.
Administrator login we set a public variable User class
<?php class Authority{ static public function check_insert(){ //声明公共变量 //检查是否具有添加留言权限 return true; } static public function check_delete(){ //检查是否具有delete权限 if(isset($_SESSION["username"]) && $_SESSION["username"]=="admin") return true; else return false; } } ?>
Set the administrator login name to: admin, and set the password to: 12345.
If the login name and password are entered correctly, you can enter the page to operate.
Judge the input login. Whether the name and password match the login name and password saved in the session.
rrreee###Encapsulate the above two classes into an authority.class.php file for later call when we implement the function.