PHP Implementation Login Module Function Example _php tips

Source: Internet
Author: User

This article describes the PHP implementation of the Landing module function method. Share to everyone for your reference, specific as follows:

I'm learning PHP recently. Learn a little about landing things, write down the memo.

Create a new four page named:
login.php
check.php
index.php
error.php

Login page to create a landing page with a form, not to say more. In the code in the JS script to determine the user name and password can not be null, empty to reset the 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 ("Please enter user name");
 Username.focus ();
 return false;
 }
 if (userpwd.value== "")
 {
 alert ("Please enter user name");
 Userpwd.focus ();
 return false;
 }
}
</script>

Check is the page, and if the password and username are correct, redirect to index.php, 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 talk about session validation. The session function is PHP's own function, used to record the user's login information, similar to cookies, but different.

We can define and use the session in the validation page, and then define and use it again on the homepage to achieve the effect of welcome mo. The above check in the code has been, 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 landing page input user name and password, if correct, will jump to the homepage, show welcome So-and-So, if the error will jump to the wrong page, display errors.

For more information about PHP interested readers can view the site topics: "Php+mysql database operations to get Started", "PHP basic Grammar Introductory Course", "PHP Operations and Operator Usage Summary", "PHP object-oriented Program Design Introductory Course", "PHP Network Programming Skills Summary", " PHP array Operation tips Encyclopedia, PHP string (String) Usage summary and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design.

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.