<?php
namespace Admin\controller;
Use Think\controller;
Class Usercontroller extends Controller {//Login verification
Public Function index () {
$user = M ("table name");
Receive the name and password in the login form
$adminname =$_post[' name '];
Password encryption, not recommended to use MD5,MD5 is not safe, testing here
$adminpwd =md5 ($_post[' pwd ');
Echo $adminname, $adminpwd;d ie;
$arr = $user->where ("database User name = ' $adminname '")->find ();
if ($arr) {
if ($arr [' Database password ']== $adminpwd)
{
Open session, with a cookie can also, suggest session
Session_Start ();
Session ("name", $adminname);
echo $_session[' name ']; Returns the corresponding value, which is received by the front end.
echo "0";
}else{
echo "1";
}
}else{
echo "2";
}
}
}
?>
"About session with the main core of the cookie, the difference before the blog is listed, here is not the difference"
"Session" Session assignment session assignment is relatively simple, direct use: Session (' Name ', ' value '); Setting sessionsession values
$value = Session (' name ');//Get all Session 3.2. Version 2 Added $value = Session ();
Session Delete Deletes the value of a session using: Session (' name ', null); Delete Name to delete all sessions, you can use: session (NULL); Clear the current session
"Cookie" cookie setting Cookie (' name ', ' value '); //
Set Cookiecookie (' name ', ' value ', 3600); Specify cookie save time cookie Gets the cookie is very simple, no matter how to set the cookie, only need to use: $value = Cookie (' name ');
If you want to get all the cookies, you can use: $value = Cookie ();
This usage is equivalent to $value = $_cookie;
Cookie deletes the value of deleting a cookie using: Cookie (' name ', null);
To delete all cookie values, you can use: Cookie (NULL); Clears all cookie values for the current set prefix
"About anti-illegal login" first create a controller named Common, inside determine whether illegal (select TP3.2 frame) schematic code is as follows:
Class Commoncontroller extends Controller
{
Public Function __construct () {
Parent::__construct ();
if (Empty ($_session[' name '))
{//session (' name ', null);
echo "Script" alert (' not logged in, please login first! '); top.location.href= '/xx/x/x; ";
}
}
}
TP framework for preventing illegal logins