PHP Implementation Login Module Function Example detailed introduction

Source: Internet
Author: User
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)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.