TP framework for preventing illegal logins

Source: Internet
Author: User

<?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

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.