This paper introduces the method of PHP to realize the function of landing module. Share to everyone for your reference, as follows:
Recently in learning PHP. Learn a little bit about landing things, write down the memo.
Create a new four page, named:
login.php
check.php
index.php
error.php
The login page uses the form to create a landing page, not much more. In the code to use the JS script to determine that the user name and password can not be null, empty is reset focus. The code is as follows:
<script type= "Text/javascript" >function JC () {var Username=document.getelementbyid ("UserName"); var userpwd= document.getElementById ("Userpwd"); if (username.value== "") {alert ("Enter user name"), Username.focus (); return false;} if (userpwd.value== "") {alert ("Enter username"); Userpwd.focus (); return false; }}</script>
Check is checking the page and redirects to index.php if the password and username are correct, otherwise directed to the error page. The code is as follows:
<? Session_Start (); $userName =$_post["UserName"]; $USERPWD =$_post["Userpwd"]; if ($userName = = "Admin" && $userPwd = = "123456") {$_session["userName"]= $userName; echo "<script type=" text/ JavaScript ' >window.location= ' index.php ';</script> '; } else {echo "<script type= ' text/javascript ' >window.location= ' error.php ';</script> ';}? >
Finally, the session verification. The session function is a PHP-brought function that records the user's login information, similar to a cookie, but differs from another.
We can define and use the session in the validation page, and then define and use it again on the homepage to achieve a welcome effect. The code in the above check is already there, the following is the code in the home page:
<?session_start ();? ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Verify that the login page to enter the user name and password, if correct, will jump to the first page, show welcome xxx, if the error will jump to the error page, display errors.
The above is the PHP implementation of the Login module function example details of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!