Http://wujiang8337.blog.163.com/blog/static/5855445200921275438614/
PHP login program
19:54:38 | category:
PHP | font size subscription
Many login programs on the Internet are complicated and cannot be understood. This should be better understood.
Login. php
<Form action = "checklogin. php" method = "Post">
<Table Height = 159 cellspacing = 0 cellpadding = 0 width = 268 align = center
Bgcolor = # ffff99 border = 0>
<Tbody>
<Tr>
<TD align = middle width = 234 Height = 43> Src = "images/login.gif" width = 359> </TD> </tr>
<Tr>
<TD align = middle background = images/loginbg.gif
Bgcolor = # fafafa Height = 180>
<Table width = 250 border = 0>
<Tbody>
<Tr>
<TD align = Middle Height = 25> account: & nbsp; <input tabindex = 1
Maxlength = 20 size = 15 name = username> </TD> </tr>
<Tr>
<TD align = middle> password: & nbsp; <input tabindex = 2
Type = PASSWORD maxlength = 20 size = 15 name = PASSWORD> </TD> </tr>
<Tr>
<TD align = Middle Height = 25> <input id = login_manager style = "border-Right: 0px; border-top: 0px; Background-image: URL (images/loginbutton.gif ); border-left: 0px; width: 52px; cursor: hand; border-bottom: 0px; Height: 18px "type = submit value =" "name = login_manager>
<Input id = login_member2 style = "border-Right: 0px; border-top: 0px; Background-image: URL (images/loginbutton2.gif); border-left: 0px; width: 52px; cursor: hand; border-bottom: 0px; Height: 18px "type = reset value =" "name = login_member2> </TD> </tr>
<Tr>
<TD align = middle>
<Table border = 0>
<Tbody>
<Tr>
<TD> </TD>
<TD width = 10> </TD>
<TD> </tr> </tbody> </table> </TD> </tr>
<Tr>
<TD align = middle background = images/loginend.gif
Height = 5> </TD> </tr> </tbody> </table> </form>
This page is a logon form.
Check for Logon
Checklogin. php
<? PHP require_once ('../connections/LR. php');?>
<? PHP
// After the form is submitted...
$ Username = trim ($ _ request ['username']);
$ Password = trim ($ _ request ['Password']);
Mysql_select_db ($ database_lr, $ LR );
$ SQL = "select username, password from Admin where username = '$ username' and Password =' $ password '";
// Obtain the query result
$ Result = mysql_query ($ SQL );
$ Userinfo = @ mysql_fetch_array ($ result );
If (! Empty ($ userinfo )){
If ($ userinfo ["username"] = $ username ){
// After the verification is passed, start the session
Session_start ();
Echo ("<meta http-equiv = Refresh content = '0; url = index. php'> ");
// Register the logon admin variable and assign the value true.
$ _ Session ["admin"] = true;
} Else {
Die ("incorrect user name and password ");
}
} Else {
Die ("incorrect user name and password ");
}
?>
This allows you to redirect errors to the logon page again.
====
Verify whether to log on, that is, the code that needs to be added on every page in the background, thus limiting access
Admin. php
<? PHP
// Prevent security risks caused by global variables
$ Admin = false;
// Start the session. This step is required.
Session_start ();
$ Lifetime = 20*60 ;//
Setcookie (session_name (), session_id (), time () + $ lifetime ,"/");
// Determine whether to log on
If (isset ($ _ session ["admin"]) & $ _ session ["admin"] = true ){
Echo "";
} Else {
// Verification Failed. Set $ _ session ["admin"] to false
$ _ Session ["admin"] = false;
Die ("You are not authorized to access ");
}
?>
The exit page is
Logout. php
<? PHP
Session_start ();
// This method destroys a previously registered variable.
Unset ($ _ session ['admin']);
Echo ("<meta http-equiv = Refresh content = '0; url = login. php'> ");
?>